@param string $sql
@param array  $bind

@return \PDOStatement
347974
protected function _execute($sql, $bind)
    {
        if (!isset($this->_prepared[$sql])) {
            if (count($this->_prepared) > 8) {
                array_shift($this->_prepared);
            }
            $this->_prepared[$sql] = @$this->_getPdo()->prepare($sql);
        }
        $statement = $this->_prepared[$sql];

        foreach ($bind as $parameter => $value) {
            if (is_string($value)) {
                $type = \PDO::PARAM_STR;
            } elseif (is_int($value)) {
                $type = \PDO::PARAM_INT;
            } elseif (is_bool($value)) {
                $type = \PDO::PARAM_BOOL;
            } elseif ($value === null) {
                $type = \PDO::PARAM_NULL;
            } elseif (is_float($value)) {
                $type = \PDO::PARAM_STR;
            } elseif (is_array($value) || $value instanceof \JsonSerializable) {
                $type = \PDO::PARAM_STR;
                $value = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
            } else {
                throw new NotSupportedException(['The `:1` type of `:2` parameter is not support', $parameter, gettype($value)]);
            }

            if (is_int($parameter)) {
                $statement->bindValue($parameter + 1, $value, $type);
            } else {
                if ($parameter[0] === ':') {
                    throw new InvalidValueException(['Bind does not require started with `:` for `:parameter` parameter', 'parameter' => $parameter]);
                }

                $statement->bindValue(':' . $parameter, $value, $type);
            }
        }

        @$statement->execute();

        return $statement;
    }
944900
public function queryFast(string $sql, $bind = []): array
    {
        $connect = $this->connectWrite();

        // 先记日志,以免错误导致无日志
        FileLog::instance()->sqlBefore('queryFast', $sql);

        //快速查询不记录查询结果日志
        if (!$bind) {
            return $connect->query($sql, \PDO::FETCH_ASSOC)->fetchAll();
        }

        //带参数绑定
        return $this->bindQuery($connect, $sql, $bind);
    }
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;
        }
    }
708052
public function build ($sql, $bind = array())
    {
        // stdclassの場合はarrayにキャスト
        if ($bind instanceof \stdClass) {
            $bind = (array) $bind;
        }

        // 配列でない場合は配列化
        if (! is_array($bind)) {
            $bind = array($bind);
        }

        // mysql strict mode 対策　STRICT_TRANS_TABLES、STRICT_ALL_TABLES
        // http://dev.mysql.com/doc/refman/5.1/ja/server-sql-mode.html
        // booleanをintに変更
        foreach($bind as $key => $val) {
            if (is_bool($val) === true) {
                $bind[$key] = (int) $val;
            }
        }

        $stmt = $this->prepare($sql);
        $stmt->execute($bind);

        return $stmt;
    }
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;
    }
1196314
public function fetchOne($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchColumn(0);
        return $result;
    }
480853
public function fetchCol($sql, $bind = array())
    {
        $stmt = $this->query($sql, $bind);
        $result = $stmt->fetchAll(Zend_Db::FETCH_COLUMN, 0);
        return $result;
    }
349250
protected function bindParam($bind)
    {
        foreach ($bind as $key => $val) {
            $param = is_numeric($key) ? $key + 1 : ':' . $key;

            if (is_array($val)) {
                array_unshift($val, $param);
                $result = call_user_func_array([$this->PDOStatement, 'bindParam'], $val);
            } else {
                $result = $this->PDOStatement->bindValue($param, $val);
            }

            if (!$result) {
                $param = array_shift($val);

                throw new BindParamException(
                    "Error occurred  when binding parameters '{$param}'",
                    $this->config,
                    $this->getLastsql(),
                    $bind
                );
            }
        }
    }
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
        );
    }
980872
public final function fetchAll($sql, array $bind = [])
    {
        return $this->query($sql, $bind)->fetchAll(\PDO::FETCH_NAMED);
    }
875159
protected function _execute($type, $sql, $bind = [])
    {
        $context = $this->_context;

        $context->sql = $sql;
        $context->bind = $bind;

        $context->affected_rows = 0;

        $this->eventsManager->fireEvent('db:before' . ucfirst($type), $this);

        if ($context->connection) {
            $connection = $context->connection;
        } else {
            $connection = $this->poolManager->pop($this, $this->_timeout);
        }

        try {
            $start_time = microtime(true);
            $context->affected_rows = $connection->execute($sql, $bind);
            $elapsed = round(microtime(true) - $start_time, 3);
        } finally {
            if (!$context->connection) {
                $this->poolManager->push($this, $connection);
            }
        }

        $count = $context->affected_rows;
        $event_data = compact('count', 'sql', 'bind', 'elapsed');
        if (is_int($context->affected_rows)) {
            $this->eventsManager->fireEvent('db:after' . ucfirst($type), $this, $event_data);
        }

        $this->logger->info($event_data, 'db.' . $type);
        return $count;
    }
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();
    }
394322
public function query($sql, $bindings = array())
    {
        list($this->pdoStatement) = $this->statement($sql, $bindings);

        return $this;
    }
269667
public function prepareExecute(string $sql, array $params): ?PDOStatement
	{
		$this->statement = $this->prepareQuery($sql, $params);
		$this->statement->execute();

		return $this->statement;
	}
222201
public function query($sql)
    {
        $this->numExecutes++;
        $this->numStatements++;
        
        $pdos = $this->_pdo->query($sql);
        
        return new PDOStatement($this, $pdos);
    }
1080740
public function bind($sql, array $params=array())
    {
        return $this->_bindInto('\?', $sql, $params, function($binder, $param) use ($sql) {
            return $binder->sqlValue($param);
        });
    }
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);
    }