Prepares a new statement on an available connection.

@param string $sql

@return \Generator

@throws FailureException
172004
private function prepareStatement(string $sql): \Generator
    {
        $connection = yield from $this->pop();
        \assert($connection instanceof Link);

        try {
            $statement = yield $connection->prepare($sql);
            \assert($statement instanceof Statement);
        } catch (\Throwable $exception) {
            $this->push($connection);
            throw $exception;
        }

        return $this->createStatement($statement, function () use ($connection) {
            $this->push($connection);
        });
    }
1333395
public function prepare(string $sql, array $driverOptions = [])
    {
        $generator = $this->__prepare($sql, $driverOptions);
        if(!$generator->valid())
        {
            return $generator->getReturn();
        }
        $current = $generator->current();
        $generator->next();
        $generator->send($current);
        return $generator->getReturn();
    }
77350
public function getOrPrepareStatement($sql)
    {
        // Return cached statements
        if (isset($this->cachedStatements[$sql])) {
            return $this->cachedStatements[$sql];
        }

        // Generate new statement
        $statement = $this->pdoConnection->prepare(
            $sql,
            array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)
        );

        // Wrap in a PDOStatementHandle, to cache column metadata
        $statementHandle = ($statement === false) ? false : new PDOStatementHandle($statement);

        // Only cache select statements
        if (preg_match('/^(\s*)select\b/i', $sql)) {
            $this->cachedStatements[$sql] = $statementHandle;
        }
        return $statementHandle;
    }
715641
public function prepare(string $sql = null)
    {
        $this->sqlQuery = $this->getConnection()->prepare($this->getSql($sql));

        return $this;
    }
589728
protected function _prepare($sql)
    {
        $connection = $this->_adapter->getConnection();
        $this->_stmt = @oci_parse($connection, $sql);
        if (!$this->_stmt) {
            /**
             * @see Zend_Db_Statement_Oracle_Exception
             */
            // require_once 'Zend/Db/Statement/Oracle/Exception.php';
            throw new Zend_Db_Statement_Oracle_Exception(oci_error($connection));
        }
    }
277916
protected function _prepare($sql)
    {
        try {
            $this->_stmt = $this->_adapter->getConnection()->prepare($sql);
        } catch (PDOException $e) {
            // require_once 'Zend/Db/Statement/Exception.php';
            throw new Zend_Db_Statement_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
1305621
function _prepareStatement()
    {
        $this->_statement = $this->_db->prepare($this->_sql);

        /* Return success if we didn't generate an error. */
        return (DB::isError($this->_statement) === false);
    }
268341
private function prepare(string $sql, array $params = []): \PDOStatement
    {
        return $this->pdo()->connectionProcess(function (Pdo $pdo) use ($sql, $params) {
            $stmt = $pdo->prepare($sql);

            if ($params) {
                $k = 1;

                foreach ($params as $key => $value) {
                    $stmt->bindValue(is_int($key) ? $k++ : $key, $value);
                }
            }

            $this->fire($sql, $params);

            $stmt->execute();

            $pdo->checkError();

            return $stmt;
        });
    }
1051170
public function prepare($sql, $options = null) {
        try {
            Log::getHandler()->debug($sql);
            $stmt = parent::prepare($sql, $options);
        } catch (PDOException $ex) {
            Log::getHandler()->error($ex->getMessage());
        }
        return $stmt;
    }
56041
protected function prepareSql($sql)
    {
        $sql = str_replace(";',", "-CODE-", $sql);
        $sql = trim($sql);
        preg_match_all('#DELIMITER (.+?)\n(.+?)DELIMITER ;#s', $sql, $m);
        foreach ($m[0] as $k => $v) {
            if ($m[1][$k] == '|') {
                throw new \RuntimeException('You can not use "|" as delimiter: '.$v);
            }
            $stored = str_replace(';', '|', $m[2][$k]);
            $stored = str_replace($m[1][$k], ";\n", $stored);
            $sql = str_replace($v, $stored, $sql);
        }
        $query = array();

        $tab = explode(";\n", $sql);
        $size = \count($tab);
        for ($i = 0; $i < $size; $i++) {
            $queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
            $queryTemp = str_replace("|", ";", $queryTemp);
            $query[] = $queryTemp;
        }

        return $query;
    }
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);
    }
637577
protected function createQueryStatement(string $sql): PDOStatement
    {
        $statement = $this->pdo->query($sql);

        if (!$statement instanceof PDOStatement) {
            throw new RuntimeException('Invalid statement');
        }

        return $statement;
    }
365705
public function execute($sql, array $parameters = array())
    {
        $this->logger->info($sql, array('parameters' => $parameters));

        try {
            $statement = $this->getPdo()->prepare($sql);
            $statement->execute($parameters);
        } catch (PDOException $exception) {
            $this->logger->error($exception->getMessage());

            throw $exception;
        }

        return $statement;
    }
992529
public function prepare(string $sql, array $params = []): Statement
    {
        if (!$stmt = sqlsrv_prepare($this->connection, $sql, $params)) {
            throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params);
        }

        return new Statement($stmt, true, $sql, $params);
    }
1197634
protected function _execute($sql)
	{
		return $this->is_write_type($sql)
			? $this->conn_id->exec($sql)
			: $this->conn_id->query($sql);
	}
879919
public function prepare(string $sql): ?\PDOStatement {
        $statement = $this->getConnection()->prepare($sql);
        if ($statement === false) {
            return null;
        }
        $this->statement = $statement;
        return $statement;
    }
125312
protected function _error($sql){
		$params = compact('sql');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			list($code, $error) = $this->error();
			throw new QueryException("{$params['sql']}: {$error}", $code);
		});
	}