Execute an SQL statement and return the boolean result.

@param  string $query
@param  array  $bindings

@return int|false
541261
public function query( $query, array $bindings = [] ) {
		return $this->run( $query, $bindings, function ( $query, $bindings ) {
			if ( $this->pretending() ) {
				return true;
			}

			// @codingStandardsIgnoreLine
			return $this->wpdb->query( $this->prepareQuery( $query, $bindings ) );
		} );
	}
1161813
public function getCypherQuery($query, array $bindings)
    {
        return new CypherQuery($this->getClient(), $query, $this->prepareBindings($bindings));
    }
1100316
protected function getSqlQuery($query, $bindings, $execTime)
    {
        $bindings = $query->bindings;
        $execTime = $query->time;
        $query = $query->sql;
    
        // need to format bindings properly
        foreach ($bindings as $i => $binding) {
            if ($binding instanceof \DateTime) {
                $bindings[$i] = $binding->format('Y-m-d H:i:s');
            } elseif (is_string($binding)) {
                $bindings[$i] = str_replace("'", "\\'", $binding);
            }
        }

        // now we create full SQL query - in case of failure, we log this
        $query = str_replace(['%', '?', "\n"], ['%%', "'%s'", ' '], $query);
        $fullSql = vsprintf($query, $bindings);

        return [$fullSql, $execTime];
    }
1309318
public function affectingStatement( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings, true );

		$result = $this->db->query( $new_query );

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

		return intval( $result );
	}
407282
public function select($query, $bindings = array())
    {
        $statement  = $this->getActivePdo()->prepare($query);

        if ($statement->execute($bindings)) {
            return $statement->fetchAll($this->fetchMode);
        }

        throw new DbException("Db execute fail [{$query}]");
    }
1264898
public function selectOne($query, $bindings = array())
    {
        $query .= " LIMIT 1;";
        $result = $this->select($query, $bindings);
        return (isset($result[0]) ? $result[0] : []);
    }
919274
public function query($query, array $binds = array())
    {
        //Argument 1 must be a string or null
        Argument::i()->test(1, 'string', self::QUERY);
        
        $request = new \stdClass();
        
        $request->query = $query;
        $request->binds = $binds;
        
        //event trigger
        $this->trigger('sql-query-before', $request);
        
        $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
            Exception::i()
                ->setMessage(Exception::QUERY_ERROR)
                ->addVariable($query)
                ->addVariable($error[2])
                ->trigger();
        }
        
        $results = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        
        if($this->queryCache) {
            //log query
            $this->queries[] = array(
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results);
        }

        //clear binds
        $this->binds = array();
        
        //event trigger
        $this->trigger('sql-query-after', $query, $binds, $results);
        
        return $results;
    }
122979
public function setQuery(string $query, $bindings = null): Query
    {
        $this->query = $query;

	    if ($bindings === null) {
		    $this->bindings = new Bindings();

	    } else if (is_array($bindings)) {
		    $this->bindings = new Bindings();
		    $this->bindings->setFromArray($bindings);

	    } else if ($bindings instanceof Bindings) {
		    $this->bindings = $bindings;

	    } else {
		    throw new \InvalidArgumentException('Invalid second argument provided, expected null, array or instance of Bindings');
	    }

        return $this;
    }
105210
public function query(string $query, array $bindings = null): Query
    {
        $this->lastQuery = new Query($query, $bindings, $this->configKey);
        return $this->lastQuery;
    }
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);
    }
891698
public function getBatchQuery($query, array $bindings) {
        return new BatchQuery($this->getClient(), $query, $this->prepareBindings($bindings));
    }
190537
public function action(string $query, array $params = [])
    {
        // Prepares the query, then stores it
        $PDOStatement = $this->pdo->prepare($query);

        // Executes the query, then returns the boolean value
        return $PDOStatement->execute($params);
    }
20212
public function cursor($query, $bindings = [], $useReadPdo = true)
    {
        $statement = $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
            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));

            $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;
        });

        while ($record = $statement->fetch()) {
            yield $record;
        }
    }
898304
public function selectOne( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_row( $query );

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

		return $result;
	}
920730
public function affectingStatement($query, $bindings = array())
    {
        return $this->run($query, $bindings, function ($me, $query, $bindings)
        {
            if ($me->pretending()) return 0;

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

            //
            $statement = $me->createPdoStatement($query);

            $statement->execute($bindings);

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

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

        return $this;
    }