Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.

@param  string $query  SQL query
@param  array  $params Query parameters
@return array
321912
public function columns(string $query, array $params = []): array
	{
		return $this->all($query, $params, PDO::FETCH_COLUMN);
	}
334486
public function query($query, $params = []) {
		$statement = $this->get_statement($query, $params);
		$statement->execute();
	}
810069
public function query($sql=null, array $params=[]) {
		if($sql === null) {
			$sql = $this->buildSQL();
			$params = $this->getParameters();
		}

		$this->replaceArrayParams($sql, $params);

		return $this->query = $this->db->query($sql, $params);
	}
333611
protected function _insert($query, $params)
    {
        $db = $this->db;
        $sth = $db->prepare($query);

        foreach ($params as $key => $val) {
            if (is_int($val)) {
                $sth->bindValue("$key", $val, $db::PARAM_INT);
            } else {
                $sth->bindValue("$key", $val);
            }
        }

        $response = $sth->execute();

        if ($response) {

            $class = $this->_rowClass;
            $row = new $class($this, $db->lastInsertId());

            return $row;
        }
        return false;
    }
730174
protected function executePreparedStatement($query, $params)
        {
            $res = odbc_prepare($this->_lnk, $query);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Prepare failed: ' . $error);
                throw new Exception('Preparing query failed ' . $error, self::PREPARE_FAILED);
            }
            $res = odbc_execute($res, $params);
            if(!$res) {
                $error = odbc_errormsg($this->_lnk);
                $this->log('Prepared query execution failed: ' . $error);
                throw new Exception('Executing prepared query failed ' . $error, self::QUERY_FAILED);
            }
            return $res;
        }
1160023
public function query($query, array $params = [])
    {
        if (!$this->nextQueryIsolationLevel) {
            return $this->retryQuery($query, $params);
        }

        [$oldLevel] = $this->setIsolationLevel($this->nextQueryIsolationLevel);
        $result = $this->retryQuery($query, $params);
        $this->setIsolationLevel($oldLevel);

        return $result;
    }
1189720
public function query($query=null, $params = [])
    {
        $result = false;
        $result_key = [];
        
        if ($query && static::isSql($query)) {
            $sql = $query;
        } else {
            $result_key = $this->getQuery()->set($query)->get('result_key');
            
            $queryType = $this->getQuery()->type();
            
            // limit select count
            if ((!$queryType || $queryType === 'select') 
                && !isset($this->getQuery()['count']) 
                && !isset($this->getQuery()['limit'])
                && !isset($this->getQuery()['pagesize'])) 
            {
                $this->getQuery()->set('limit', 1000);
            }
            
            // update must set where
            if (($queryType === 'update' || $queryType === 'delete') && !$this->getQuery()->get('where')) {
                Ioc::logger('db')->error('query no set where: ' . json_encode($this->getQuery()->all()));
                return false;
            }
            
            $sql = $this->parse();
        }
        
        if ($params) {
            $this->bindParams($params);
        }
        
        $this->lastSql = $this->formatSql($sql);
        
        // sql log
        Ioc::logger('db')->debug($sql);
        
        try {
            $this->getAdapter()->prepare($sql);
            if (!empty($this->binds)) {
                $this->getAdapter()->bindParams($this->binds);
            }
            $bool = $this->getAdapter()->execute();
            
            if (!$bool) {
                throw new Exception($this->getAdapter()->getErrorMessage());
            }
        } catch (Exception $e) {
            
            $this->getAdapter()->rollback();
            throw new Exception('Excute sql error: ' . $e->getMessage() . ', sql:' . $sql);
        }
        
        $rawStatement = explode(" ", $sql);
        $statement = strtolower(trim($rawStatement[0]));
        
        if ($statement === 'show') {
            $result = $this->getAdapter()->fetchAll($fetchmode);
        } elseif ($statement === 'select') {
            $rkeys = $result_key ? StringHelper::toArray($result_key, ',\s') : null;
            
            while($rs = $this->getAdapter()->fetch()) {
                // 如果指定返回结果集的key，则按key重组数据
                if ($rkeys) {
                    if (count($rkeys) == 1) {
                        $rk1 = trim($rkeys[0]);
                        if (isset($rs[$rk1])) {
                            $result[$rs[$rk1]] = $rs;
                        } else {
                            $result[] = $rs;
                        }
                    } elseif (count($rkeys) == 2) {
                        $rk1 = trim($rkeys[0]);
                        $rk2 = trim($rkeys[1]);
                        if (!empty($rk2)) {
                            $result[$rs[$rk1]][$rs[$rk2]] = $rs;
                        } else {
                            $result[$rs[$rk1]][] = $rs;
                        }
                    }
                } else {
                    $result[] = $rs;
                }
            }
        } elseif ($statement === 'update' || $statement === 'delete') {
            $result = $this->getAdapter()->numberOfRows();
        } elseif ($statement === 'insert') {
            $result = $this->getAdapter()->lastId();
        } else {
            return null;
        }
        
        return $result;
    }
911331
public static function setParams($query, array $params = []) {
        Str::assert($query, 'query');

        return array_reduce($params, function($query, $param) {
            $param = self::getStringRepresentation($param);

            return strpos($query, '?') ? substr_replace($query, $param, strpos($query, '?'), strlen('?')) : $query;
        }, $query);
    }
1141130
public function queryColumn($sql = null,$params = array())
	{
		if(!isset($this->operationOption['params']))
		{
			$this->operationOption['params'] = array();
		}
		$this->prepareQuery($sql ? $sql : $this->buildSelectSQL(),$params);
		if(false === $this->lastStmt)
		{
			return false;
		}
		else
		{
			return $this->lastStmt->fetchAll(PDO::FETCH_COLUMN);
		}
	}
1040986
public function count($query, array $params = [])
    {
        $stmt = $this->connection->prepare($query);
        $stmt->execute($params);
        return $stmt->fetchColumn();
    }
330768
function queryColumn($query)
  {
    $data = [];
    $res = $this->q($query);
    while ($row = $res->fetch_row())
    {
      if ($res->field_count == 1)
        $data[] = $row[0];
      else
        $data[$row[0]] = $row[1];
    }
    $res->close();
    return $data;
  }
364378
protected function prepare(string $query, array $params): array
    {
        try {
            $statement = $this->getPDO()->prepare($query);
        } catch (PDOException $e) {
            throw new PDOException($e->getMessage() . ' [ ' . $this->replaceParams($query, $params) . ' ] ',
                (int)$e->getCode(), $e->getPrevious());
        }

        return ['query' => $query, 'params' => $params, 'statement' => $statement];
    }
44261
public function executeQuery($query, array $params = []) {
        $storage = $this->getStorage();
        $cacheKey = null;
        $cacheLength = null;

        // Determine cache key and lengths
        if ($query instanceof Query) {
            $cacheKey = $query->getCacheKey();
            $cacheLength = $query->getCacheLength();

        } else if (!is_array($query)) {
            throw new InvalidQueryException('Query must be a command array or a Titon\Db\Query instance');
        }

        // Use the storage engine first
        if ($cacheKey) {
            if ($storage && $storage->has($cacheKey)) {
                return $storage->get($cacheKey);

            // Fallback to driver cache
            // This is used to cache duplicate queries
            } else if ($this->hasCache($cacheKey)) {
                return $this->getCache($cacheKey);
            }
        }

        // Execute the query using the dialect
        $db = $this->getConnection()->selectDB($this->getDatabase());
        $dialect = $this->getDialect();
        $startTime = microtime();

        // Direct query command
        if (is_array($query)) {
            $response = $db->command($query, $params);

        // Using query object
        } else {
            if ($query->getType() === Query::CREATE_TABLE) {
                $response = $dialect->executeCreateTable($db, $query);

            } else {
                $type = $query->getType();
                $method = 'execute' . ucfirst($type);

                if (!method_exists($dialect, $method)) {
                    throw new UnsupportedQueryStatementException(sprintf('Query statement %s does not exist or has not been implemented', $type));
                }

                $response = call_user_func_array([$dialect, $method], [$db->selectCollection($query->getTable()), $query]);
            }
        }

        // Gather and log result
        if (is_array($response)) {
            $response['startTime'] = $startTime;

            if (isset($response['id'])) {
                $this->_lastID = $response['id'];
            }
        } else {
            $this->_lastID = null;
        }

        if (is_array($query)) {
            $response['command'] = $query;

            $this->_result = new MongoResultSet($response);
        } else {
            $this->_result = new MongoResultSet($response, $query);
        }

        $this->logQuery($this->_result);

        // Return and cache result
        if ($cacheKey) {
            if ($storage) {
                $storage->set($cacheKey, $this->_result, $cacheLength);
            } else {
                $this->setCache($cacheKey, $this->_result);
            }
        }

        return $this->_result;
    }
1143592
public function search($query, array $params = [])
    {
        $params['q'] = $query;
        $this->results = $this->retrieveAll('/search.json', $params);

        return $this->results;
    }
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();

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

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

        return $data;
    }
617737
public function queryValue($params = array())
    {
        $this->mergeParams($params);
        $this->beginQuery();
        $rst = $this->statement->fetchColumn();
        $this->statement->closeCursor();

        return $rst;
    }