Skip to content

Add try block in _prepareQuery #793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions MysqliDb.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1905,20 +1905,30 @@ protected function _buildLimit($numRows)
*/
protected function _prepareQuery()
{
$stmt = $this->mysqli()->prepare($this->_query);
try {
$stmt = $this->mysqli()->prepare($this->_query);
} catch (Exception $e) {
//try to reconnect gracefully if the connection was broken since the last query
if ($this->mysqli()->errno === 2006 && $this->autoReconnect === true && $this->autoReconnectCount === 0) {
$this->connect($this->defConnectionName);
$this->autoReconnectCount++;
return $this->_prepareQuery();
}
}

if ($stmt !== false) {
if ($this->traceEnabled)
$this->traceStartQ = microtime(true);
return $stmt;
}

//if statement is false then the server has been down for awhile and the query is dirty, reconnect and reset
//we'll lose one query exection, but the next will be successful
if ($this->mysqli()->errno === 2006 && $this->autoReconnect === true && $this->autoReconnectCount === 0) {
$this->connect($this->defConnectionName);
$this->autoReconnectCount++;
return $this->_prepareQuery();
}

$error = $this->mysqli()->error;
$query = $this->_query;
$errno = $this->mysqli()->errno;
Expand Down