Fetches the first column of all SQL result rows as an array.

@param string|Zend_Db_Select $sql An SQL SELECT statement.
@param mixed $bind Data to bind into SELECT placeholders.
@return array
480853
public function fetchCol($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchAll(Zend_Db::FETCH_COLUMN, 0);
        return $result;
    }
1049639
protected function query($conn, $sql)
    {
        $items = array();
        if ($conn instanceof PDO) {
            $result = $conn->query($sql);
            if ($result) {
                foreach ($result as $row) {
                    $items[] = $row[0];
                }
            }
        } elseif (is_resource($conn)) {
            $result = sqlsrv_query($conn, $sql);
            if ($result) {
                while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC)) {
                    $items[] = $row[0];
                }
            }
        }
        return $items;
    }
951147
public function fetchCol($sql, $bind = array())
    {
        try {
            $sth = $this->query($sql, $bind);
            if ($sth === false) {
                return false;
            }
            $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);
            return $result;
        } catch (PDOException $e) {
            throw new DbException("Error query: " . $e->getMessage());
        }
    }
1307572
protected function query($sql) {
        $vars = func_get_args();
		$cleaner = "/[\s,].+|[^a-zA-Z]/";
		$illegal = "/[\\\\'\"\%]/";
        try {
            $pdo = $this->dbConnect();
            $stmt = $pdo->prepare($sql);
            $binds = explode(':', $sql);
            foreach($binds as $n => $b) {
				if($n != 0 && substr($b,1)!=false) {
					$b = ':' . preg_replace($cleaner,'',$b);
					$vars[$n] = preg_replace($illegal,'',$vars[$n]);
					$stmt->bindParam($b,$vars[$n]);
				}
            }
            $stmt->execute();
            return (strpos($sql,'SELECT') !== FALSE) ? $stmt->fetchAll() : true;
        } catch(PDOException $e) {
            return array('query_error' => $e);
        }
    }
699244
public function query(string $sql, $bind = []): Statement
    {
        $this->operation = 'query';
        $this->params = $bind;
        $this->sql = $sql;
        return $this;
    }
459290
public function executeFast(string $sql, $bind = [])
    {
        if (!$bind) {
            return $this->connectWrite()->exec($sql);
        }
        return $this->bindExecute($this->connectWrite(), $sql, $bind);
    }
326577
function insertSql($table, array $bind)
    {
        // extract and quote col names from the array keys
        $cols = array();
        $vals = array();
        $this->extractAndQuoteCols($bind, $cols, $vals);
        // build the statement
        $sql = "INSERT INTO "
            . $this->wrappedAdapter->quoteIdentifier($table, true)
            . ' (' . implode(', ', $cols) . ') '
            . 'VALUES (' . implode(', ', $vals) . ')';
        return $sql;
    }
1080330
public function queryCache($sql, $bind = []) {
        $redis = Cache::redis();
        if (!$redis) {
            //没有使用 redis 不支持二级缓存
            return null;
        }
        $key = $this->cacheKey($sql, $bind);
        $cache_name = $this->cacheName($sql);
        $result = Cache::hashGet($cache_name, $key);
        if ($result) {
            Log::debug("命中缓存" . $sql . json_encode($bind), 'cache');
        }
        return $result;
    }
17563
public function run($sql, $bind = "")
    {
        $this->_sql = trim($sql);
        $this->_bind = $this->cleanup($bind);
        $this->_error = "";

        try {
            $start = microtime(true);
            $pdostmt = $this->prepare($this->_sql);
            if ($pdostmt->execute($this->_bind) !== false) {
                if (preg_match("/^(" . implode("|", array("select", "describe", "pragma")) . ") /i", $this->_sql))
                {
                    $return = ($this->limit == 1)? $pdostmt->fetch(\PDO::FETCH_ASSOC) : $pdostmt->fetchAll(\PDO::FETCH_ASSOC);
                }
                elseif (preg_match("/^(" . implode("|", array("delete", "update")) . ") /i", $this->_sql))
                {
                    $return = $pdostmt->rowCount();
                }
                elseif (preg_match("/^(" . implode("|", array("insert")) . ") /i", $this->_sql))
                {
                    $return = $this->lastInsertId();
                }
            }


            if ($this->print) {
                $time = microtime(true) - $start;
                $queryPreview = $this->interpolateQuery($this->_sql, $this->_bind);
                print_r($queryPreview);
            }

            return $return;

        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            if($this->print) {
                $queryPreview = $this->interpolateQuery($this->_sql, $this->_bind);
                print_r($queryPreview);
            }
            $this->debug();
            return false;
        }
    }
477613
protected function getSelectSql(array $sql): array
    {
        $sql[] = trim('SELECT ' . trim(implode(' ', [
            $this->distinct,
            $this->highPriority,
            $this->straightJoin,
            $this->resultSize,
            $this->bufferResult,
            $this->calcFoundRows,
        ])));

        return $sql;
    }
34970
public static function read($sql, $mode = self::KEY)
    {
        $vals = [];
        $result = self::query($sql);
        while ($row = $result->fetch($mode)) {
            $vals[] = $row;
        }
        //
        return $vals;
    }
542784
public function select( $query, $bindings = [ ], $useReadPdo = true, $resultClass = null )
	{
		$fetchCustomClass = ! is_null($resultClass) && class_exists($resultClass);

		return $this->run( $query, $bindings, function ( $query, $bindings ) use ( $useReadPdo, $fetchCustomClass, $resultClass ) {
			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 ), ! $fetchCustomClass );
			$this->bindValues( $statement, $this->prepareBindings( $bindings ) );
			$statement->execute();

			return $fetchCustomClass ? $statement->fetchAll(\PDO::FETCH_CLASS, $resultClass) : $statement->fetchAll();
		});
	}
87271
public function custom($sql, $bind = array())
    {
        // Prepare query
        $query = ConnectionManager::getConnection()->prepare($sql);

        // Bind when needed
        if (count($bind) > 0) {
            $numericBinding = true;

            // Check if we are going to use the numeric binding
            foreach($bind as $key => $value) {
                if (is_int($key)) {
                    continue;
                }else{
                    $numericBinding = false; // @codeCoverageIgnore
                    if (substr($key, 0, 1) !== ':') { // @codeCoverageIgnore
                        throw new QueryException("When binding, you should use numeric keys or keys with : before each key to identify the binding place in the query!"); // @codeCoverageIgnore
                    } // @codeCoverageIgnore
                }
            }

            // Bind it!
            $idx = 1;
            foreach($bind as $key => $value) {
                if ($numericBinding) {
                    if (is_int($value)) {
                        $type = \PDO::PARAM_INT; // @codeCoverageIgnore
                    } elseif(is_bool($value)) {
                        $type = \PDO::PARAM_BOOL; // @codeCoverageIgnore
                    } else {
                        $type = \PDO::PARAM_STR;
                    }
                    $query->bindValue($idx, $value, $type);
                } else {
                    $query->bindValue($key, $value);
                }
            }
        }

        // Set fetch mode
        $query->setFetchMode(\PDO::FETCH_CLASS, $this->class);

        // Execute
        $query->execute();

        // Fetch and return
        return $this->injectState($query->fetchAll());
    }
266547
public function selectValues($sql)
    {
        $result = $this->execute($sql);
        if ($result->count()) {
            $values = [];
            foreach ($result as $row) {
                $values[] = reset($row);
            }
            return $values;
        }
    }
829512
function fetch_arrays($sql)
    {
        $rs   = $this->query($sql);
        $data = [];
        while (true == ($row = $rs->fetch_assoc())) {
            $data[] = $row;
        }
        $rs->free();
        return $data;
    }
205112
protected function _fetch(Zend_Db_Table_Select $select)
    {
        $stmt = $this->_db->query($select);
        $data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
        return $data;
    }
403460
public function queryFirstPDO($sql, array $params = array())
    {
        $query_id = $this->_queryPDO($sql, $params);
        if ($query_id === false) {
            return false;
        }
        $out = $this->_fetchPDO();
        $this->_freeResultPDO();
        return $out;
    }