Basecoat\DB::execute PHP Method

execute() public method

Execute a prepare statement to data binding values. Can be called repeatedly for the same prepared query, with different data bindings.
public execute ( $bindings = [], boolean $useMaster = false ) : integer
$useMaster boolean set to TRUE to use the master server connection
return integer returns number of rows that were affected, or -1 if query failed
    public function execute($bindings = array(), $useMaster = false)
    {
        static $retries = 0;
        $debug = null;
        if ($useMaster) {
            $sth =& self::$msth;
            $connectionLabel = self::$mConnectionLabel;
        } else {
            $sth =& $this->sth;
            $connectionLabel = $this->connectionLabel;
        }
        $qStartTime = round(microtime(true), 3);
        if ($sth->execute($bindings)) {
            $result = $sth->rowCount();
            // Check if we need to run an explain for debugging
            if ($this->debug > 0) {
                $dbh = $useMaster ? self::$mdbh : $this->dbh;
                $debug = $this->explainQuery($this->lastQuery, $bindings, $dbh);
            }
            if ($retries > 0) {
                $retries = 0;
            }
        } else {
            $this->logErrorInfo($sth, $connectionLabel);
            // Check for dropped connection
            if (in_array($this->errorCode, self::$reconnect_on_error) && $retries == 0) {
                $retries++;
                $this->connect($useMaster, true);
                $result = $this->execute($bindings, $useMaster);
            } else {
                $debug = $this->errorMsg;
                $result = -1;
            }
        }
        $qTime = round(microtime(true), 3) - $qStartTime;
        $this->updateProfiling($this->lastQuery, $bindings, $qTime, $result, $connectionLabel, $debug);
        return $result;
    }