Execute an SQL statement and return the boolean result.

@param  string  $query
@param  array   $bindings
@return bool
437874
public function statement($query, $bindings = array())
	{
		return $this->run($query, $bindings, function($me, $query, $bindings)
		{
			if ($me->pretending()) return true;

			$bindings = $me->prepareBindings($bindings);

			return $me->getPdo()->prepare($query)->execute($bindings);
		});
	}
889306
protected function compileJoinPart(Query $query, array &$bindings): string
    {
        $joinsSQL = [];

        foreach ($query->join as $join) {
            $joinsSQL[] = $this->compileOneJoin($join, $bindings);
        }

        return $this->implodeSQL($joinsSQL);
    }
408269
protected function runPrepared($query, array $bindings, $fetchMode=null)
    {
        return $this->attempt(function () use ($query, $bindings) {

            $statement = $this->prepared($query, $bindings);
            $statement->execute();

            return $statement;
        }, $query);

    }
536086
protected function checkBindings(string $query, array $bindings)
    {
        $bindingsCountInQuery = $this->countBindingsFromQuery($query);
        $bindingsCount = count($bindings);

        if ($bindingsCountInQuery !== $bindingsCount) {
            throw QueryMapperException::wrongBindingsNumber($bindingsCountInQuery, $bindingsCount);
        }

        $this->checkBindingsPolicy($bindings);
    }
707058
protected function execute(string $query, array $bindings = [])
    {
        $query = N1qlQuery::fromString($query);
        $query->consistency($this->consistency);
        $query->crossBucket($this->crossBucket);
        $query->positionalParams($bindings);
        $result = $this->executeQuery($query);
        $this->metrics = $result->metrics ?? [];

        return $result;
    }
222875
protected function handleQueryException( $e, $query, $bindings ) {
		if ( $result = apply_filters( 'awethemes.database.handle_query_exception', null, $e, $query, $bindings ) ) {
			return $result;
		}

		throw $e;
	}
225678
public function query($query, array $binds = [], $fetch = null)
    {
        $request = new StdClass();

        $request->query = $query;
        $request->binds = $binds;

        $connection = $this->getConnection();
        $query      = (string) $request->query;
        $stmt       = $connection->prepare($query);

        //bind some more values
        foreach ($request->binds as $key => $value) {
            $stmt->bindValue($key, $value);
        }

        //PDO Execute
        if (!$stmt->execute()) {
            $error = $stmt->errorInfo();

            //unpack binds for the report
            foreach ($binds as $key => $value) {
                $query = str_replace($key, "'$value'", $query);
            }

            //throw Exception
            throw SqlException::forQueryError($query, $error[2]);
        }

        //clear binds
        $this->binds = [];

        if (!is_callable($fetch)) {
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

            //log query
            $this->log([
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results
            ]);

            return $results;
        }

        if ($fetch instanceof Closure) {
            $fetch = $fetch->bindTo($this, get_class($this));
        }

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            if (call_user_func($fetch, $row, $this) === false) {
                break;
            }
        }

        return $this;
    }
697433
public function execute($query)
    {
        $this->_queries[] = $query;

        $sql = is_string($query) ? $query : $query->getString();

        $resultSQL = $this->getAdapter()->execute($sql);
        $result = new Result($resultSQL, $this->getAdapter());
        $result->setQuery($query);

        return $result;
    }
915575
public function exec($sql = "", $bindingValues = array(), $insert = true)
    {
        //Check if the query is a SELECT|INSERT|UPDATE and :variation is available
        if (preg_match("/.*(SELECT|INSERT|UPDATE|SHOW|DELETE).*/", $sql)) {
            
            $this->sql = $sql;

            //Always prepare the SQL statement first
            $query = $this->connection->prepare($sql);

            if (preg_match('/\s*:(.+?)\s/', $sql)) {
                if (is_array($bindingValues) && !empty($bindingValues)) {
                    foreach ($bindingValues as $key => $val) {
                        //Clean the bindingValues. Check if they start with :
                        if (!preg_match('/:.*/', $key)) {
                            $bindingValues[":" . $key] = $val;
                            unset($bindingValues[$key]);
                        }
                    }
                }


                //Add the binding variables to the query
                if ($query->execute($bindingValues)) {
                    return $this->getLastInsertID();
                } else {
                    //@ToDo:When the save or update fails make sure we handle the error gracefully!
                    throw new \Exception(implode("\n", $query->errorInfo()));
                }

            } else {
                $result = $query->execute();
            }

            if (preg_match('/.*(SELECT|SHOW).*/', $sql)) {
                $query->setFetchMode(\PDO::FETCH_ASSOC);
                return $query->fetchAll();
            }

            return $result;
        }


        return false;
    }
736154
protected function affectingStatement($query, $bindings = array())
    {
        $statement  = $this->getActivePdo()->prepare($query);

        $statement->execute($bindings);

        return $statement->rowCount();
    }
929214
protected function queryHandler($query, $bindings, $time, $connectionName)
    {
        $data = ['connectionName' => $connectionName];

        if ($this->recordSqlBindings) {
            $data['bindings'] = $bindings;
        }

        Integration::addBreadcrumb(new Breadcrumb(
            Breadcrumb::LEVEL_INFO,
            Breadcrumb::TYPE_USER,
            'sql.query',
            $query,
            $data
        ));
    }
396482
public function select($query, $bindings = [], $useReadPdo = true)
    {
        return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
            if ($this->pretending()) {
                return [];
            }

            // For select statements, we'll simply execute the query and return an array
            // of the database result set. Each element in the array will be a single
            // row from the database table, and will either be an array or objects.
            $statement = $this->prepared($this->getPdoForSelect($useReadPdo)
                              ->prepare($query));

            $this->bindValues($statement, $this->prepareBindings($bindings));

            $statement->execute();

            return $statement->fetchAll();
        });
    }
418332
public function cursor( $query, $bindings = [], $useReadPdo = true )
	{
		$statement = $this->run( $query, $bindings, function ( $me, $query, $bindings ) use ( $useReadPdo )
		{
			if ( $me->pretending() )
			{
				return [];
			}

			$statement = $this->getPdoForSelect( $useReadPdo )->prepare( $query );

			$fetchMode = $me->getFetchMode();
			$fetchArgument = $me->getFetchArgument();

			if ( $fetchMode === PDO::FETCH_CLASS && !isset( $fetchArgument ) )
			{
				$fetchArgument = 'StdClass';
			}

			if ( isset( $fetchArgument ) )
			{
				$statement->setFetchMode( $fetchMode, $fetchArgument, $me->getFetchConstructorArgument() );
			}
			else
			{
				$statement->setFetchMode( $fetchMode );
			}

			$statement->execute( $me->prepareBindings( $bindings ) );

			return $statement;
		} );

		while ( $record = $statement->fetch() )
		{
			yield $record;
		}
	}
867594
public function executeProcedure($procedureName, array $bindings = [])
    {
        $stmt = $this->createStatementFromProcedure($procedureName, $bindings);

        $stmt = $this->addBindingsToStatement($stmt, $bindings);

        return $stmt->execute();
    }
394322
public function query($sql, $bindings = array())
    {
        list($this->pdoStatement) = $this->statement($sql, $bindings);

        return $this;
    }
1335935
final public function loadFromQuery($query, array $binds = [])
    {
        $this->source()->loadItemFromQuery($query, $binds, $this);
        return $this;
    }
774553
public function cursor( $query, $bindings = [ ], $useReadPdo = true, $resultClass = null )
	{
		$fetchCustomClass = ! is_null($resultClass) && class_exists($resultClass);

		$statement = $this->run( $query, $bindings, function ( $query, $bindings ) use ( $useReadPdo, $fetchCustomClass ) {
			if( $this->pretending() )
			{
				return [ ];
			}

			// First we will create a statement for the query. Then, we will set the fetch
			// mode and prepare the bindings for the query. Once that's done we will be
			// ready to execute the query against the database and return the cursor.
			$statement = $this->prepared( $this->getPdoForSelect( $useReadPdo )->prepare( $query ), ! $fetchCustomClass );
			$this->bindValues(
				$statement, $this->prepareBindings( $bindings )
			);

			// Next, we'll execute the query against the database and return the statement
			// so we can return the cursor. The cursor will use a PHP generator to give
			// back one row at a time without using a bunch of memory to render them.

			$statement->execute();
			return $statement;
		});

		if( $fetchCustomClass )
		{
			while( $record = $statement->fetchObject( $resultClass ) )
			{
				yield $record;
			}
		}
		else
		{
			while( $record = $statement->fetch() )
			{
				yield $record;
			}
		}
	}