准备执行语句并返回一个语句对象
@param string $sql
@param array $driverOptions
@return IStatement
@throws DbException
483167
public function prepare(string $sql, array $driverOptions = [])
    {
        $isCache = !isset($driverOptions['IMI_NO_CACHE']) || $driverOptions['IMI_NO_CACHE'];
        if($isCache && $stmtCache = StatementManager::get($this, $sql))
        {
            $stmt = $stmtCache['statement'];
        }
        else
        {
            // 处理支持 :xxx 参数格式
            $this->lastSql = $sql;
            $this->lastStmt = $this->instance->prepare($sql, $driverOptions);
            if(false === $this->lastStmt)
            {
                throw new DbException('sql prepare error: [' . $this->errorCode() . '] ' . $this->errorInfo() . PHP_EOL . 'sql: ' . $sql . PHP_EOL);
            }
            $stmt = BeanFactory::newInstance(Statement::class, $this, $this->lastStmt);
            if($isCache)
            {
                $stmtCache = StatementManager::get($this, $sql);
                if($stmtCache)
                {
                    StatementManager::unUsingStatement($stmtCache['statement']);
                }
                else
                {
                    StatementManager::set($stmt, true);
                }
            }
        }

        return $stmt;
    }
686312
public function prepare(string $sql, array $params = []): Statement
    {
        if (!$stmt = $this->connection->prepare($sql)) {
            $error = [
                'error' => $this->connection->error,
                'errno' => $this->connection->errno,
                'sqlstate' => $this->connection->sqlstate
            ];

            throw new SqlException('Failed to prepare statement', [$error], $sql, $params);
        }

        if (!empty($params)) {
            if (!$stmt->bind_param(self::getMysqlParamTypes($params), ...$params)) {
                throw new SqlException('Failed to bind params', $stmt->error_list, $sql, $params);
            }
        }

        return new Statement($stmt, $this->usedPrepare, $sql, $params);
    }
595507
private function _exec($sql, $arguments = array())
    {
        $sql = $this->replaceArgs($sql, $arguments);

        // executes the statement
        $result = $this->_conn->query($sql);
        if ($this->_conn->errno > 0) {
            throw new DbException(
                "Failed to execute the statement: " .
                "({$this->_conn->errno}) {$this->_conn->error}"
            );
        }

        return $result;
    }
607851
public function execute($sql = null, $parameters = array()) {
        if (empty($sql)) {
            return null;
        }
        foreach ($parameters as $key => $item) {
            Str::bindParam($sql, $key + 1, $item, is_numeric($item) ? 'INT' : 'STR');
        }
        $this->result = mysql_query($sql, $this->driver);
        Factory::log()->info(sprintf('MYSQL: %s => %s', $sql,
            $this->getError()));
        return $this->result;
    }
224452
public function select($sql, $parameters = array()) {
		if ($this->configs['result_type'] == 'object'
            || $this->configs['result_type'] == '{}'
            || $this->configs['result_type'] === true) {
            return $this->getObject($sql, $parameters);
        }
        return $this->getArray($sql, $parameters);
	}
226221
public function query(string $sql, array $params = []) {
        X::logger()->trace("$sql with params " . $this->serializeArray($params));
        try {
            $st = $this->pdo->prepare($sql);
            if ($st === false) {
                $e = $this->pdo->errorInfo();
                throw new DataBaseException($e[2], $e[1]);
            }
            if ($st->execute($params)) {
                $this->_affectedRows = $st->rowCount();
                $this->_lastInsertId = $this->pdo->lastInsertId();
                return $st->fetchAll(PDO::FETCH_ASSOC);
            }

            $e = $st->errorInfo();
            throw new DataBaseException($e[2], $e[1]);
        } catch (PDOException $ex) {
            X::logger()->trace($ex);
            throw new DataBaseException($ex->getMessage(), $ex->getCode());
        }
    }
276664
public function execute($sql, $params = array())
    {
        $kvm = KVMLogger::instance('anycontent-database');

        /** @var \PDO $db */
        $dbh = $this->getConnection();

        $stmt = $dbh->prepare($sql);

        $kvm->startStopWatch('anycontent-query-execution-time');

        $stmt->execute($params);

        $duration = $kvm->getDuration('anycontent-query-execution-time');
        $message  = $kvm->createLogMessage($this->debugQuery($sql, $params), [ 'duration' => $duration ]);
        $kvm->debug($message);
        
        $this->queryCounter++;

        return $stmt;
    }
428292
public function with($option = null, $driver = null)
    {
        return $this->option($option)->driver($driver);
    }
415754
private function executeSql(PDO $pdo, $sql, array $parameters = null) {
        $this->lastPdo = $pdo;
        $this->lastSql = $sql;
        $this->lastParameters = $parameters;

        try {
            $pdoStmt = $pdo->prepare($sql);
            $pdoStmt->execute($parameters);
            return $pdoStmt;
        } catch (Exception $ex) {
            $errMsg = '执行SQL语句出错，错误消息：' . $ex->getMessage() . ', SQL：' . $this->getLastSql();
            $this->logger->error($errMsg);

            return false;
        }
    }
809111
public function prepare($sql, array $driverOptions = array())
    {
        $this->numStatements++;

        $pdos = $this->_pdo->prepare($sql, $driverOptions);
        
        return new PDOStatement($this, $pdos);
    }
664819
protected function execSQL($sql)
    {
        // Check and ignore empty statements
        if (trim($sql) == "") {
            return;
        }

        try {
            $this->totalSql++;

            if (!$this->autocommit) {
                $this->conn->beginTransaction();
            }

            $stmt = $this->conn->prepare($sql);
            $this->log(sprintf('    Executing statement "%s"', $sql), Project::MSG_VERBOSE);
            $stmt->execute();
            $this->log(sprintf('    %d rows affected', $stmt->rowCount()), Project::MSG_VERBOSE);

            if (!$this->autocommit) {
                $this->conn->commit();
            }

            $this->goodSql++;
        } catch (PDOException $e) {
            $this->log("Failed to execute: " . $sql, Project::MSG_ERR);
            if ($this->onError != "continue") {
                throw $e;
            }
            $this->log($e->getMessage(), Project::MSG_ERR);
        }
    }
498860
public static function query($sql) {
        self::init();
        try {
            $db = self::connect();
            if(is_array($db)) {
                throw new DbException('Connection error');
            }
            if(!$query = $db->query($sql)) {
                throw new DbException('Failed to execute query!');
            }
        } catch(mysqli_sql_exception $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);

        } catch(DbException $e) {
            self::$_ops->formatError([], $e->getMessage(), $sql);
        }
        if(isset($query) && isset($db)) {
            return ['result' => $query, 'link' => $db];
        }
    }
1014560
private function executeSqlQuery($sql)
    {
        try {
            $result = (bool) Database::statement($sql);
        } catch (\Exception $exception) {
            echo "\n\033[0;31m▶\033[00m $sql\n";
            throw $exception;
        }

        echo "\033[0;32m▶\033[00m $sql\n";

        return $this;
    }
487349
public function prepare($driver_options = array())
	{
		if ($this->query_sql === null) {
			$this->compile();
		}

		return $this->pdo->prepare($this->query_sql, $driver_options);
	}
366941
public function run_update($sql, array $params=null, array $driverOptions=array()) {
		return($this->run_query($sql, $params, $driverOptions));
	}
145107
public static function execute( $sql, $parameters = null, $connection = null, $fetchMode = \PDO::FETCH_ASSOC )
    {
        self::$_statement = self::createStatement( $sql, $connection, $fetchMode );

        if ( empty( $parameters ) )
        {
            return self::$_statement->execute();
        }

        return self::$_statement->execute( $parameters );
    }
676801
function prepare($sql, $driver_options = [])
    {
//        if (isset($this->statements[$sql])){
//            return $this->statements[$sql];
//        }
        if ($this->trace_sql || $this->trace_count){
            $stmt = parent::prepare($this->addPrefixes($sql), $driver_options);
            if ($stmt instanceof PDOStatement){
                return /*$this->statements[$sql] = */new DBStatementDebug($stmt, $this->trace_sql, $this->trace_count, $this->slow_query);
            }else{
                throw new Error('PDO does not return PDOStatement');
            }
        }
        return /*$this->statements[$sql] = */parent::prepare($this->addPrefixes($sql), $driver_options);
    }