@param       $sql
@param array $binds

@return mixed
4830
public function prepareSQL($sql, $binds = [])
    {
        $prepare = $this->getConnection()->prepare($sql);

        if (!$prepare) {
            throw new Exception('Cannot prepare statement');
        }

        $this->bindBinds($prepare, $binds);

        $prepare->setFetchMode(\PDO::FETCH_OBJ);

        return $prepare;
    }
1160007
public function bind(string $query, array $bindings): string
    {
        $this->checkBindings($query, $bindings);
        $escapedBindings = $this->escapeBindings($bindings);

        $query = str_replace('%', '%%', $query);
        $query = str_replace('?', '%s', $query);

        $query = call_user_func_array('sprintf', array_merge([$query], $escapedBindings));

        return $query;
    }
247570
protected function bindValues(/*# string */ $sql, array $settings)/*# : string */
    {
        // init bindings
        $this->bindings = [];

        // bind values
        return $this->getBuilder()->getParameter()
            ->bindValues($sql, $this->bindings, $settings);
    }
669490
public function getRealSql($sql, array $bind = [])
    {
        foreach ($bind as $key => $val) {
            $value = is_array($val) ? $val[0] : $val;
            $type  = is_array($val) ? $val[1] : PDO::PARAM_STR;
            if (PDO::PARAM_STR == $type) {
                $value = $this->quote($value);
            } elseif (PDO::PARAM_INT == $type) {
                $value = (float)$value;
            }
            // 判断占位符
            $sql = is_numeric($key) ?
                substr_replace($sql, $value, strpos($sql, '?'), 1) :
                str_replace(
                    [':' . $key . ')', ':' . $key . ',', ':' . $key . ' '],
                    [$value . ')', $value . ',', $value . ' '],
                    $sql . ' ');
        }
        return rtrim($sql);
    }
540734
public function query($sql, $bind = [], $master = false, $class = false)
    {
        return $this->connection->query($sql, $bind, $master, $class);
    }
378883
private function logSql($sql, array $bind = []) {
        if (!Config::get('app', 'debug')) {
            return;
        }
        if ($bind) {
            foreach ($bind as $key => $val) {
                $value = is_array($val) ? $val[ 0 ] : $val;
                $type = is_array($val) ? $val[ 1 ] : PDO::PARAM_STR;
                if (PDO::PARAM_STR == $type) {
                    $value = $this->pdo->quote($value);
                } elseif (PDO::PARAM_INT == $type && '' === $value) {
                    $value = 0;
                }
                // 判断占位符
                $sql = is_numeric($key) ? substr_replace($sql, $value, strpos($sql, '?'), 1) : str_replace([':' . $key . ')',
                                                                                                            ':' . $key . ',',
                                                                                                            ':' . $key . ' '], [$value . ')',
                                                                                                                                $value . ',',
                                                                                                                                $value . ' '], $sql . ' ');
            }
        }
        $this->queryStr = rtrim($sql);
        Log::debug($this->queryStr, 'sql');
        return;
    }
13119
public function query(string $sql, $bind = []): Result
    {
        $result = parent::query($sql, $bind);
        return new Result($this->tableName, $result);
    }
699244
public function query(string $sql, $bind = []): Statement
    {
        $this->operation = 'query';
        $this->params = $bind;
        $this->sql = $sql;
        return $this;
    }
496044
public function process($sql)
    {
        $bindFormatted=[];
        $bindRaw=[];
        foreach ($this->bindings as $key => $value) {
            if (is_array($value)) {
                $valueSet = implode(', ', $value);

                $values = array_map(
                    function ($value) {
                        return ValueFormatter::formatValue($value);
                    },
                    $value
                );

                $formattedParameter = implode(',', $values);
            } else {
                $valueSet           = $value;
                $formattedParameter = ValueFormatter::formatValue($value);
            }

            if ($formattedParameter !== null) {
                $bindFormatted[$key]=$formattedParameter;
            }

            if ($valueSet !== null) {
                $bindRaw[$key]=$valueSet;
            }
        }

        for ($loop=0;$loop<2;$loop++)
        {
            // dipping in binds
            // example ['A' => '{B}' , 'B'=>':C','C'=>123]
            $sql=$this->compile_binds($sql,$bindRaw,'#{([\w+]+)}#');
        }
        $sql=$this->compile_binds($sql,$bindFormatted,'#:([\w+]+)#');

        return $sql;
    }
973213
public function orderByRaw(string $sql, array $bindings = []): BaseQueryRelateContract
    {
        $this->query->orderByRaw($sql, $bindings);

        return $this;
    }
1177010
public function query($sql, array $params = array())
    {
        //$helper = $this->getHelper();
        $con = $this->establishConnection();
        $sth = $con->prepare($sql, array(Connection::ATTR_CURSOR => Connection::CURSOR_SCROLL));

        // bind params
        foreach($params as $key => $value){
            $type = Connection::PARAM_STR;
            if ( is_null($value) ) {
                $type = Connection::PARAM_NULL;
            } elseif ( is_int($value) ) {
                $type = Connection::PARAM_INT;
            } elseif ( is_bool($value) ) {
                $type = Connection::PARAM_BOOL;
            } elseif ( is_resource($value) ) {
                $type = Connection::PARAM_LOB;
            }
            if ( is_int($key) ) {
                $sth->bindValue($key + 1, $value, $type);
            } else {
                $sth->bindValue($key, $value, $type);
            }
        }

        $result = $sth->execute();
        return $sth;
    }
189939
public function execute(string $sql, $bind = []): Statement
    {
        $this->operation = 'execute';
        $this->sql = $sql;
        $this->params = $bind;
        return $this;
    }
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;
    }
1176928
public function query($sql, $bind = array())
    {
        // connect to the database if needed
        $this->_connect();

        // is the $sql a Zend_Db_Select object?
        if ($sql instanceof Zend_Db_Select) {
            if (empty($bind)) {
                $bind = $sql->getBind();
            }

            $sql = $sql->assemble();
        }

        // make sure $bind to an array;
        // don't use (array) typecasting because
        // because $bind may be a Zend_Db_Expr object
        if (!is_array($bind)) {
            $bind = array($bind);
        }

        // prepare and execute the statement with profiling
        $stmt = $this->prepare($sql);
        $stmt->execute($bind);

        // return the results embedded in the prepared statement object
        $stmt->setFetchMode($this->_fetchMode);
        return $stmt;
    }
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;
    }
1196314
public function fetchOne($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchColumn(0);
        return $result;
    }
9021
public function bindValues(
        /*# string */ $sql,
        array &$bindings,
        array $settings
    )/*# : string */ {
        // make sure escape function ok
        $this->setEscapeCallable($settings['escapeFunction']);

        // replace each placeholder with corresponding ?/:name/value
        return preg_replace_callback(
            '/\b__PHQUERY_[^_]++__\b/',
            function ($m) use (&$bindings, $settings) {
                return $this->replacePlaceholders($m[0], $bindings, $settings);
            },
            $sql
        );
    }