Executes a SELECT query and returns an array where the first column is used as keys and the second as values.

@param  string $query  SQL query
@param  array  $params Query parameters
@return array
11220
public function pairs(string $query, array $params = []): array
	{
		return $this->all($query, $params, PDO::FETCH_KEY_PAIR);
	}
413071
final public function queryArray(string $query)
    {
        $result = $this->queryResult($query);
        if (false === $result) {
            return false;
        }

        $return = [];
        while (false !== $row = $result->fetchRow()) {
            $return[] = $row;
        }
        return $return;
    }
1188224
public function query($query, array $params = [])
    {
        $this->query  = $query;
        $this->params = $params;
        $this->send();

        return $this;
    }
1333799
public function query(string $query, array $params = []): bool
	{
		return $this->execute($this->prepare($query, $params));
	}
223388
public static function executeRow1(string $query): array
  {
    self::logQuery($query);

    return self::$dl->executeRow1($query);
  }
1169731
public function findAllByQuery($query, array $params = array()) {
		//Not using the parent findAllByQuery() implementation, becaus
		//it performs one-by-one EAV fetching, which is very bad for performance.
		//Instead, we find all main records with 1 query. And then fine all EAV entries (for all),
		//with a single additional query (instead of one per main record).

		$records = array();
		$recordIds = array();
		foreach ($this->db->fetchAll($query, $params) as $data) {
			$records[] = $data;
			$recordIds[] = $data['_id'];
		}

		$dataPerNamespaceFlattened = $this->pullEavDataForAll($recordIds);

		$results = array();
		foreach ($records as $data) {
			$data['__eav_data__'] = $dataPerNamespaceFlattened[$data['_id']];
			$results[] = $this->loadModel($data);
		}

		return $results;
	}
1193735
protected function prepareQueryAndParams(string $query, array $params): array
	{
		// Replace IN clause placeholder with escaped values

		replace:

		if(strpos($query, '([?])') !== false)
		{
			foreach($params as $key => $value)
			{
				if(is_array($value))
				{
					array_splice($params, $key, 1, $value);

					$query = preg_replace('/\(\[\?\]\)/', '(' . trim(str_repeat('?, ', count($value)), ', ') . ')', $query, 1);

					goto replace;
				}
			}
		}

		// Return query and parameters

		return [$query, $params];
	}
1360244
public function single($query = '', $params = null)
    {
        $query = trim($query);
        if (empty($query)) {
            $query = $this->build();
            if (!$params) {
                $params = $this->getBindValues();
            }
        }

        $this->resetAll();
        $this->lastSql = $query;

        $this->execute($query, $params);
        return $this->sQuery->fetchColumn();
    }
355332
public function select($query, $bindings = array()) {
        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->getBatchQuery($query, $bindings);
                    return $statement->getResultSet();
                    
                    // $statement = $me->getCypherQuery($query, $bindings);
                    // return $statement->getResultSet();

                });
    }
686562
public static function run($query, $params=array()) {
		
		$self = static::getInstance();
		
		$self->openConnection();
		
		$ret = NULL;
		
		try {
			
			// prepare query
			$stat = $self->handler->prepare($query);

			// bind parameters
			$stat->execute((array)$params);

			// count affected rows
			$affected = $stat->rowCount();
			
		} catch (\PDOException $e) {
			
			// logger
			$self->logParamQuery($query, 0, $params);
			
			switch ($e->getCode()) {
				
				// integrity constraint violation
				/*
				 case '23000':
					 $message = 'Database integrity constraint violation';
					 break;
				 */
				default:
					$message = $e->getMessage();
					break;
			}
			
			$self->addError($message);
			
			$affected = 0;
			
		} catch (\Exception $e) {
			
			// logger
			$self->logParamQuery($query, 0, $params);
			$self->addError($e->getMessage());
			$affected = 0;
			
		}
		
		$stat->closeCursor();
		$self->logParamQuery($query, $affected, $params);
		
		return $affected;
			
	}
590965
public function executeFetchOne(
        $query = null,
        $params = []
    ) {

        $this->execute($query, $params);
        return $this->fetchOne();
    }
940666
protected function execute($query)
    {
        $query->execute($this->bindings);
        
        $this->bindings = [];
        $this->wheres   = [];

        return $query;
    }
735130
public function executeAndFetchArray($query, $parameters = [])
    {
        $statement = $this->link->prepare($query);

        $statement->execute($parameters);
        $data = $statement->fetch(PDO::FETCH_COLUMN);
        $statement->closeCursor();

        return $data;
    }
1038047
protected function namedParams(&$query, &$params)
    {
        if (!is_array($params)) {
            return;
        }

        $pattern = "a-zA-Z0-9_";

        if (!preg_match("/\?([" . $pattern . "]+)/", $query)) {
            return;
        }

        $oldParams = $params;
        $params = [];

        reset($oldParams);
        $this->modifyQuery($query, function($part) use(&$params, &$oldParams, $pattern) {
            return preg_replace_callback("/\?([" . $pattern . "]*)([^" . $pattern . "]|$)/", function($match) use(&$params, &$oldParams) {
                if ($key = $match[1]) {
                    $params[] = $oldParams[$key];
                } else {
                    $params[] = current($oldParams);
                    next($oldParams);
                }
                return "?" . $match[2];
            }, $part);
        });
    }
802539
private function interpolateQuery($query, array $params)
    {
        $keys = array();
        $values = $params;

        # build a regular expression for each parameter
        foreach ($params as $key => $value) {
            if (is_string($key)) {
                $keys[] = '/:'.$key.'/';
            } else {
                $keys[] = '/[?]/';
            }

            if (is_array($value)) {
                $values[$key] = implode(',', $value);
            }

            if (is_null($value)) {
                $values[$key] = 'NULL';
            }
        }
        // Walk the array to see if we can add single-quotes to strings
        array_walk($values, create_function('&$v, $k', 'if (!is_numeric($v) && $v!="NULL") $v = "\'".$v."\'";'));

        $query = preg_replace($keys, $values, $query, 1);

        return $query;
    }
256367
public function first(string $query, array $params = [], ...$fetchMode)
	{
		$prepared = $this->prepare($query, $params);

		$this->execute($prepared);

		if(!empty($fetchMode))
		{
			$prepared['statement']->setFetchMode(...$fetchMode);
		}

		return $prepared['statement']->fetch();
	}
1173039
public function query($query, array $params = [])
    {
        $this->lastStatement = $this->getPDO()->prepare($query);
        $this->lastStatement->execute($this->prepareParams($params));
        return $this->lastStatement;
    }