Basecoat\DB::prepare PHP Method

prepare() public method

Prepare a query for execution by the execPrepared function
public prepare ( string $query, boolean $useMaster = false, array $attr = null )
$query string the query string, may contain data binding placeholder for use by execPrepared
$useMaster boolean set to TRUE to use the master server connection
$attr array custom PDO attributes to set $return int whether statement was successfully prepared (1), or not (-1)
    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;
    }