public function prepare($query, $useMaster = false, $attr = null)
{
if ($this->connect($useMaster) == -1) {
return -2;
}
if (is_null($attr)) {
$attr = array(\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY);
}
$this->lastQuery = $query;
if ($useMaster) {
$sth =& self::$msth;
$dbh =& self::$mdbh;
self::$msth = self::$mdbh->prepare($query, $attr);
$connectionLabel = self::$mConnectionLabel;
} else {
$sth =& $this->sth;
$dbh =& $this->dbh;
$this->sth = $this->dbh->prepare($query, $attr);
$connectionLabel = $this->connectionLabel;
}
if ($sth === false) {
$this->logErrorInfo($dbh, $connectionLabel);
// Check for dropped connection
if (in_array($this->errorCode, self::$reconnect_on_error) && $retries == 0) {
$retries++;
$this->connect($useMaster, true);
$result = $this->prepare($query, $useMaster, $attr);
} else {
$result = -1;
}
} else {
$result = 1;
}
$sth->setFetchMode(\PDO::FETCH_ASSOC);
return $result;
}