develpup/doctrine-oci8-extended

支持游标的Doctrine OCI8驱动程序。

dev-master 2019-05-09 13:11 UTC

This package is auto-updated.

Last update: 2024-09-23 12:02:21 UTC


README

支持游标的Doctrine OCI8驱动程序。

用法

$config = new Doctrine\DBAL\Configuration();
$params = [
    'dbname'      => 'database_sid',
    'user'        => 'database_username',
    'password'    => 'database_password',
    'host'        => 'database.host',
    'port'        => 1521,
    'persistent'  => true,
    'driverClass' => 'Doctrine\DBAL\Driver\OCI8Ext\Driver',
];
$conn = Doctrine\DBAL\DriverManager::getConnection($params, $config);

$stmt = $conn->prepare('BEGIN MY_STORED_PROCEDURE(:user_id, :cursor); END;');
$stmt->bindValue('user_id', 42);
$stmt->bindParam('cursor', $cursor, \PDO::PARAM_STMT);
$stmt->execute();

/** @var $cursor Doctrine\DBAL\Driver\OCI8Ext\OCI8Cursor */
$cursor->execute();

while ($row = $cursor->fetch()) {
    print_r($row);
    echo PHP_EOL;
}

$cursor->closeCursor();
$stmt->closeCursor();

类型

对于不由 PDO::PARAM_ 常量表示的 OCI8 类型,将 OCI8::PARAM_ 常量作为 bindValue()bindParam()type 参数传递。

游标

游标可以指定为 PDO::PARAM_STMTOCI8::PARAM_CURSOR 或仅为 'cursor'。只能使用 bindParam() 方法将游标绑定到语句。

子游标

结果集列中返回的游标资源会自动检索。您可以通过传递以下之一来更改此行为 检索模式 标志

  • OCI8::RETURN_RESOURCES 返回原始PHP资源。
  • OCI8::RETURN_CURSORS 返回尚未执行的 OCI8Cursor 对象。
use Doctrine\DBAL\Driver\OCI8Ext\OCI8;

$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC+OCI8::RETURN_CURSORS);
$rows = $stmt->fetchAll(\PDO::FETCH_BOTH+OCI8::RETURN_RESOURCES);