Run an SQL statement and get the number of rows affected.

@param  string $query
@param  array  $bindings

@return int
193577
public function affectingStatement($query, $bindings = [])
    {
        $statement = $this->execute($query, $bindings);
        return $statement->rowCount();
    }
453207
public function affectingStatement($query, $bindings = [])
    {
        $start = $this->getLogTime();

        try {

            $result = $this->wpdb->query($this->bindParams($query, $bindings, true));

            if ($result === false || $this->wpdb->last_error) {
                throw new QueryException($query, $bindings, new \Exception($this->wpdb->last_error));
            }

            return intval($result);

        } catch (QueryException $e) {
            throw $e;
        } finally {
            $this->logQuery($query, $bindings, $this->getElapsedTime($start));
        }
    }
970666
private function bind_params( $query, $bindings, $update = false )
	{

		$query    = str_replace( '"', '`', $query );
		$bindings = $this->prepareBindings( $bindings );

		if ( ! $bindings ) {
			return $query;
		}

		$bindings = array_map( function ( $replace )
		{
			if ( is_string( $replace ) ) {
				$replace = "'" . esc_sql( $replace ) . "'";
			} elseif ( $replace === null ) {
				$replace = "null";
			}

			return $replace;
		}, $bindings );

		$query = str_replace( [ '%', '?' ], [ '%%', '%s' ], $query );
		$query = vsprintf( $query, $bindings );

		return $query;
	}
97065
public function statement( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings, true );

		return $this->unprepared( $new_query );
	}
1193145
public function select($query, $bindings = array(),$useReadPdo = false)
    {
        return $this->run($query, $bindings, function(self $me, $query, array $bindings)
        {
            if ($me->pretending()) return array();

            // 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
            // node from the database, and will either be an array or objects.
            $statement = $me->getCypherQuery($query, $bindings);

            return $statement->getResultSet();
        });
    }
548897
public function prepare($query, array $bindings=[])
    {
        $statement = $this->statement($query);

        $this->callBeforeListeners('prepare',[$query, $bindings]);

        $prepared = (new PDOPrepared(
            $statement,
            $query,
            $this->getOption(self::RETURN_LAST_AFFECTED),
            $this->errorHandler
        ))->bind($bindings);

        $this->callAfterListeners('prepare',[$query, $bindings, $prepared]);

        return $prepared;

    }
563387
public function statement($query, $bindings = [])
    {
        $new_query = $this->bindParams($query, $bindings, true);

        return $this->unprepared($new_query);
    }
4812
public function select($query, $bindings = array(), $useReadPdo = true)
	{
		return $this->run($query, $bindings, function($me, $query, $bindings) use ($useReadPdo)
		{
			if ($me->pretending()) return array();

			// 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->getPdoForSelect($useReadPdo)->prepare($query);

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

			return $statement->fetchAll($me->getFetchMode());
		});
	}
1306073
public function select($query, $bindings = [], $useReadPdo = true)
    {
        $query .= ' ALLOW FILTERING';

        return $this->statement($query, $bindings);
    }
572994
public function insert($query, array $bindings=[], $returnLastInsertId=null)
    {
        $returnLastInsertId = $returnLastInsertId !== null
                              ? $returnLastInsertId
                              : $this->getOption(static::RETURN_LAST_ID);


        $this->callBeforeListeners('insert',[$query, $bindings]);

        $result = $bindings ? $this->runPrepared($query, $bindings)
                            : $this->writeUnprepared($query);

        $this->callBeforeListeners('insert',[$query, $bindings]);

        return $returnLastInsertId ? $this->lastInsertId() : null;
    }
222875
protected function handleQueryException( $e, $query, $bindings ) {
		if ( $result = apply_filters( 'awethemes.database.handle_query_exception', null, $e, $query, $bindings ) ) {
			return $result;
		}

		throw $e;
	}
307332
protected function countBindingsFromQuery(string $query)
    {
        preg_match_all($this->getBindingPattern(), $query, $matches);

        return count($matches[0] ?? []);
    }
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);

    }
263470
public function logQuery($connection, $query, array $bindings, $time)
    {
        if (! empty($bindings)) {
            $query = vsprintf(
                // Replace pdo bindings to printf string bindings escaping % char.
                str_replace(['%', '?'], ['%%', "'%s'"], $query),

                // Convert all query attributes to strings.
                $this->normalizeQueryAttributes($bindings)
            );
        }

        // Finish query with semicolon.
        $query = rtrim($query, ';') . ';';

        $this->queries[] = compact('connection', 'query', 'time');
    }
1088994
public function statement($query, $bindings = array(), $rawResults = false)
    {
        return $this->run($query, $bindings, function(self $me, $query, array $bindings) use($rawResults)
        {
            if ($me->pretending()) return true;

            $statement = $me->getCypherQuery($query, $bindings);

            $result = $statement->getResultSet();

            return ($rawResults === true) ? $result : $result instanceof ResultSet;
        });
    }
634798
protected function compileFromPart(Query $query, array &$bindings): string
    {
        if ($query->table === null) {
            throw new InvalidQueryException('The FROM table is not set');
        }

        return 'FROM '.$this->compileIdentifierWithAlias($query->table, $query->tableAlias, $bindings);
    }
1122602
public function query(string $sql, array $bindings = []): IQueryBuilderHandler
    {
        $queryObject = new QueryObject($sql, $bindings, $this->getConnection());
        $this->connection->setLastQuery($queryObject);

        $this->fireEvents(EventHandler::EVENT_BEFORE_QUERY, $queryObject);

        [$response, $executionTime] = $this->statement($queryObject->getSql(), $queryObject->getBindings());

        $this->fireEvents(EventHandler::EVENT_AFTER_QUERY, $queryObject, [
            'execution_time' => $executionTime,
        ]);

        $this->pdoStatement = $response;

        return $this;
    }