@param string $sql
@param array  $bind
@param int    $fetchMode
@param bool   $useMaster

@return array
486305
public function query($sql, $bind = [], $fetchMode = \PDO::FETCH_ASSOC, $useMaster = false)
    {
        $sql = $this->_replaceQuoteCharacters($sql);

        try {
            $statement = $bind ? $this->_execute($sql, $bind) : @$this->_getPdo()->query($sql);
        } catch (\PDOException $e) {
            $failed = true;

            if ($this->_transaction_level === 0 && !$this->_ping()) {
                try {
                    $this->close();
                    $statement = $bind ? $this->_execute($sql, $bind) : @$this->_getPdo()->query($sql);
                    $failed = false;
                } catch (\PDOException $e) {

                }
            }

            if ($failed) {
                throw new DbException([
                    ':message => ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind',
                    'message' => $e->getMessage(),
                    'sql' => $sql,
                    'bind' => json_encode($bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
                ], 0, $e);
            }
        }

        return $statement->fetchAll($fetchMode);
    }
262260
public function query($sql, $bind = [], $master = false, $pdo = false)
    {
        $this->initConnect($master);

        if (!$this->linkID) {
            return false;
        }

        // 记录SQL语句
        $this->queryStr = $sql;

        $this->bind = $bind;

        Db::$queryTimes++;

        try {
            // 调试开始
            $this->debug(true);

            // 预处理
            $this->PDOStatement = $this->linkID->prepare($sql);

            // 是否为存储过程调用
            $procedure = in_array(strtolower(substr(trim($sql), 0, 4)), ['call', 'exec']);

            // 参数绑定
            if ($procedure) {
                $this->bindParam($bind);
            } else {
                $this->bindValue($bind);
            }

            // 执行查询
            $this->PDOStatement->execute();

            // 调试结束
            $this->debug(false, '', $master);

            // 返回结果集
            return $this->getResult($pdo, $procedure);
        } catch (\PDOException $e) {
            if ($this->isBreak($e)) {
                return $this->close()->query($sql, $bind, $master, $pdo);
            }

            throw new PDOException($e, $this->config, $this->getLastsql());
        } catch (\Throwable $e) {
            if ($this->isBreak($e)) {
                return $this->close()->query($sql, $bind, $master, $pdo);
            }

            throw $e;
        } catch (\Exception $e) {
            if ($this->isBreak($e)) {
                return $this->close()->query($sql, $bind, $master, $pdo);
            }

            throw $e;
        }
    }
225678
public function query($query, array $binds = [], $fetch = null)
    {
        $request = new StdClass();

        $request->query = $query;
        $request->binds = $binds;

        $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
            throw SqlException::forQueryError($query, $error[2]);
        }

        //clear binds
        $this->binds = [];

        if (!is_callable($fetch)) {
            $results = $stmt->fetchAll(PDO::FETCH_ASSOC);

            //log query
            $this->log([
                'query'     => $query,
                'binds'     => $binds,
                'results'   => $results
            ]);

            return $results;
        }

        if ($fetch instanceof Closure) {
            $fetch = $fetch->bindTo($this, get_class($this));
        }

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            if (call_user_func($fetch, $row, $this) === false) {
                break;
            }
        }

        return $this;
    }
1184546
public function pdoQuery($sql = '', $bindWhereParam = [])
    {
        // Check empty query
        if (empty($sql)) {
            self::error('Query is empty..');
        }

        // clean query from white space
        $sql = trim($sql);
        // get operation type
        $operation = explode(' ', $sql);
        // make first word in uppercase
        $operation[0] = strtoupper($operation[0]);

        // set class property with pass value
        $this->sql = $sql;
        // set class statement handler
        $this->STH = $this->prepare($this->sql);

        // check valid sql operation statement
        if (!in_array($operation[0], $this->validOperation)) {
            self::error('invalid operation called in query. use only ' . implode(', ',
                    $this->validOperation) . ' You can have NO SPACE be between ' . implode(', ',
                    $this->validOperation) . ' AND parms');
        }

        // sql query pass with no bind param
        if (count($bindWhereParam) <= 0) {

            // try catch block start
            try {
                // execute pdo statement
                if ($this->STH->execute()) {
                    // get affected rows and set it to class property
                    $this->affectedRows = $this->STH->rowCount();
                    // set pdo result array with class property
                    $this->results = $this->STH->fetchAll();
                    // close pdo cursor
                    $this->STH->closeCursor();
                    // return pdo result
                    return $this;
                } else {
                    self::error($this->STH->errorInfo()); // if not run pdo statement sed error
                }
            } catch (\PDOException $e) {
                self::error($e->getMessage() . ': ' . __LINE__);
            } // end try catch block
        } elseif (count($bindWhereParam) > 0) {  // if query pass with bind param

            $this->data = $bindWhereParam;
            // start binding fields
            // bind pdo param
            $this->_bindPdoParam($bindWhereParam);
            // use try catch block to get pdo error
            try {
                // run pdo statement with bind param
                if ($this->STH->execute()) {
                    // check operation type
                    switch ($operation[0]) {
                        case 'SELECT':
                            // get affected rows by select statement
                            $this->affectedRows = $this->STH->rowCount();
                            // get pdo result array
                            $this->results = $this->STH->fetchAll();
                            // return PDO instance
                            return $this;
                            break;
                        case 'INSERT':
                            // return last insert id
                            $this->lastId = $this->lastInsertId();
                            // return PDO instance
                            return $this;
                            break;
                        case 'UPDATE':
                            // get affected rows
                            $this->affectedRows = $this->STH->rowCount();
                            // return PDO instance
                            return $this;
                            break;
                        case 'DELETE':
                            // get affected rows
                            $this->affectedRows = $this->STH->rowCount();
                            // return PDO instance
                            return $this;
                            break;
                    }
                    // close pdo cursor
                    $this->STH->closeCursor();
                } else {
                    self::error($this->STH->errorInfo());
                }
            } catch (\PDOException $e) {
                self::error($e->getMessage() . ': ' . __LINE__);
            } // end try catch block to get pdo error
        } else {
            self::error('Error Query');
        }
    }
516700
public function update($table, $set, $where, $bind = array())
    {
        $sql = "UPDATE " . $table . " SET ";

        if(is_array($set)) {
            foreach($set as $field => $value) {
                $sql .= $field ." = ". $value . ",";
            }

            $sql = rtrim($sql,",");

        }else{
            $sql .= $set;
        }


        $sql .= " WHERE " . $where . ";";

        $bind = $this->cleanup($bind);

        return $this->run($sql, $bind);
    }
540734
public function query($sql, $bind = [], $master = false, $class = false)
    {
        return $this->connection->query($sql, $bind, $master, $class);
    }
917965
public function sqlFetchPairs(string $sql, array $params = [], string $key = '0', string $value = '1'): array
    {
        $stmt = $this->prepare($sql, $params);

        $pairs = [];

        while ($record = $stmt->fetch()) {
            $pairs[array_key_exists($key, $record) ? $record[$key] : null] = array_key_exists($value, $record) ? $record[$value] : null;
        }

        return $pairs;
    }
140101
public function exec(string $sql, array $bind = []): FetchAbstract
    {
        if ($bind) {
            $stmt = $this->handle->prepare($sql);
            foreach ($bind as $name => $val) {
                $type = $this->getArgType($val);
                $stmt->bindValue(':' . $name, $val, $type);
            }

            $result = $stmt->execute();
        } else {
            $result = $this->handle->query($sql);
        }

        return new SqliteFetch($sql, $result);
    }
1150230
public function fetchPairs($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $data = array();
        while ($row = $stmt->fetch(Zend_Db::FETCH_NUM)) {
            $data[$row[0]] = $row[1];
        }
        return $data;
    }
1080740
public function bind($sql, array $params=array())
    {
        return $this->_bindInto('\?', $sql, $params, function($binder, $param) use ($sql) {
            return $binder->sqlValue($param);
        });
    }
1192942
public function query(string $sql, $bind = [])
    {
        $sql = trim($sql);

        // 执行前置 钩子
        $ret = $this->before('Query', $sql, $bind);
        if ($ret === self::INTERRUPT) {
            return null;
        }
        list($sql, $bind) = $ret;

        //修正查询参数
        $this->statement->query($sql, $bind);

        // 如果允许多表访问,直接通过
        if ($this->enableMulti()) {
            // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
            return $this->after('Query', self::query2());
        }

        // 取表名
        $table = $this->statement->getTable();
        $tables = count($table);

        // 如果未识别出表名,有可能是库操作
        if (!$tables) {
            // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
            return $this->after('Query', self::query2());
        }

        // 如果识别出多个表名
        if ($tables > 1) {
            trigger_error('查询语句中不允许同时指定多个表名:' . json($tables), E_USER_ERROR);
        }

        // 只有一个表
        $table = $table[0];

        // 如果语句中的表名与初始化时不同,则错误
        if ($table != $this->tableName) {
            trigger_error('表名不匹配:' . $this->tableName . ':' . $this->statement->getSql(), E_USER_ERROR);
        }

        // 调用 父类的 查询语句获取结果, 执行后置钩子进行转换
        return $this->after('Query', self::query2());
    }
704755
public static function execute($sql,$bind=[])
    {
        try{
            $bind=is_array($bind) ? $bind : [$bind];
            self::$db=Connect::boot();
            Connect::comSql($sql);
            $sth = self::$db->prepare($sql);
            $sth->execute($bind);
            return $sth->rowCount();
        } catch (\PDOException $e) {
            throw new Exception($e->getMessage());
        }
    }
1106813
public function delete($table, $where = [], array $bind = [])
    {
        $table = $this->quote()->identifier($table);
        $sql   = "DELETE FROM $table";
        if (is_array($where)) {
            $where = $this->createWhereExpression($where);
        }
        $sql .= (($where) ? " WHERE {$where}" : '');

        $stmt = $this->query($sql, $bind);

        return $stmt->rowCount();
    }
965246
protected function bindParams(&$sql, array $bind = [])
    {
        foreach ($bind as $key => $value) {
            if (is_array($value)) {
                $name = $this->bind($value[0], $value[1], isset($value[2]) ? $value[2] : null);
            } else {
                $name = $this->bind($value);
            }

            if (is_numeric($key)) {
                $sql = substr_replace($sql, ':' . $name, strpos($sql, '?'), 1);
            } else {
                $sql = str_replace(':' . $key, ':' . $name, $sql);
            }
        }
    }
631714
public function execute($sql, $bind = [], $has_insert_id = false)
    {
        $sql = $this->_replaceQuoteCharacters($sql);

        try {
            $r = $bind ? $this->_execute($sql, $bind)->rowCount() : @$this->_getPdo()->exec($sql);
            if ($has_insert_id) {
                return $this->_getPdo()->lastInsertId();
            } else {
                return $r;
            }
        } catch (\PDOException $e) {
            throw new DbException([
                ':message => ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind',
                'message' => $e->getMessage(),
                'sql' => $sql,
                'bind' => json_encode($bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
            ]);
        }
    }
621784
public function select($table, $components = array(), $bind = "")
    {
        $default_components = array(
            'fields'    => '*',
            'groupby'   => '',
            'having'    => '',
            'where'     => '',
            'orderby'   => '',
            'limit'     => ''
        );

        $components = array_merge($default_components,$components);
        $components = array_filter($components);
        $sql = "";
        foreach($components as $key => $value) {

            switch($key) {
                case 'fields':
                    $sql .= "SELECT " . $value . " FROM " . $table;
                    break;

                case 'where':
                    $sql .= " WHERE " . $value;
                    break;

                case 'groupby':
                    $sql .= " GROUP BY " . $value;
                    break;

                case 'having':
                    $sql .= " HAVING " . $value;
                    break;

                case 'orderby':
                    $sql .= " ORDER BY " . $value;
                    break;

                case 'limit':
                    $sql .= " LIMIT " . $value;
                    if($value == 1)$this->limit = $value;
                    break;
            }

        }
        $sql .= ";";

        return $this->run($sql, $bind);
    }
545950
public function queryAndFetch($sql) {
		$q = $this->query($sql);
		if (empty($q)) {
			return array();
		}
		$res = array();
		while ($l = ($this->fetch($q))) {
			$res[] = $l;
		}
		return $res;
	}