public function select($query, $bindings = null, $useMaster = false, $fetchAll = false)
{
static $retries = 0;
if ($this->connect($useMaster) == -1) {
return -2;
}
$debug = null;
$sth = null;
if ($useMaster) {
$dbh =& self::$mdbh;
if (is_object(self::$msth)) {
self::$msth->closeCursor();
}
self::$msth =& $sth;
$connectionLabel = self::$mConnectionLabel;
} else {
$dbh =& $this->dbh;
if (is_object($this->sth)) {
$this->sth->closeCursor();
}
$this->sth =& $sth;
$connectionLabel = $this->connectionLabel;
}
// Clear result holder
$this->selectResult = array();
$this->lastQuery = $query;
if (is_null($bindings)) {
$qStartTime = round(microtime(true), 3);
$sth = $dbh->query($query);
$qTime = round(microtime(true), 3) - $qStartTime;
if ($sth === false) {
$this->logErrorInfo($dbh, $connectionLabel);
$debug = $this->errorMsg;
// Check for dropped connection
if (in_array($this->errorCode, self::$reconnect_on_error) && $retries == 0) {
$retries++;
$this->connect($useMaster, true);
$result = $this->select($query, $bindings, $useMaster, $fetchAll);
} else {
$result = -1;
}
} else {
$result = $sth->rowCount();
if ($retries > 0) {
$retries = 0;
}
// Check if we need to run an explain for debugging
if ($this->debug > 0) {
$debug = $this->explainQuery($query, null, $dbh);
}
}
$this->updateProfiling($query, $bindings, $qTime, $result, $connectionLabel, $debug);
} else {
$presult = $this->prepare($query, $useMaster);
if ($presult > 0) {
$result = $this->execute($bindings, $useMaster);
// Check if we need to run an explain for debugging
if ($this->debug > 0) {
$debug = $this->explainQuery($query, $bindings, $dbh);
}
}
}
if ($result > -1) {
if ($fetchAll) {
if ($this->fetchAll($this->selectResult, null, false, $useMaster) == -1) {
return -1;
}
}
return $result;
} else {
return $result;
}
}