Coder Social home page Coder Social logo

ecphp / doctrine-oci8 Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 137 KB

Doctrine's OCI8 (Oracle) driver with cursor support.

Home Page: https://ecphp-doctrine-oci8.readthedocs.io

License: Other

Shell 0.32% PHP 99.68%
doctrine oci8 oci database cursor oracle

doctrine-oci8's Introduction

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Type Coverage Code Coverage Read the Docs License

Doctrine OCI8 Driver

The Doctrine OCI8 driver with cursor support, for PHP >= 7.4.

This is a fork of the original package develpup/doctrine-oci8-extended from Jason Hofer.

Installation

composer require ecphp/doctrine-oci8

Configuration

Symfony 5

Use the ecphp/doctrine-oci8-bundle to automatically configure the parameters.

If you prefer modifying the configuration, edit the doctrine.yaml as such:

doctrine:
    dbal:
        driver_class: EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Driver
        types:
            cursor:  EcPhp\DoctrineOci8\Doctrine\DBAL\Types\CursorType

Usage

<?php

namespace App;

use Doctrine\DBAL\Types\Type;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Types\CursorType;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Driver;

include __DIR__ .'/vendor/autoload.php';

// Register the custom type.
if (false === Type::hasType('cursor')) {
    Type::addType('cursor', CursorType::class);
}

$config = new Doctrine\DBAL\Configuration();
$params = [
    'dbname'      => 'database_sid',
    'user'        => 'database_username',
    'password'    => 'database_password',
    'host'        => 'database.host',
    'port'        => 1521,
    'persistent'  => true,
    'driverClass' => Driver::class, // This is where we load the 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 EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\OCI8Cursor */
$cursor->execute();

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

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

Types

For OCI8 types that are not represented by PDO::PARAM_ constants, pass OCI8::PARAM_ constants as the type argument of bindValue() and bindParam().

Cursors

Cursors can be specified as PDO::PARAM_STMT, OCI8::PARAM_CURSOR, or just 'cursor'. Only the bindParam() method can be used to bind a cursor to a statement.

Sub-Cursors

Cursor resources returned in a column of a result set are automatically fetched. You can change this behavior by passing in one of these fetch mode flags:

  • OCI8::RETURN_RESOURCES to return the raw PHP resources.
  • OCI8::RETURN_CURSORS to return the OCI8Cursor objects that have not yet been executed.
use Doctrine\DBAL\Driver\OCI8\OCI8;

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

Special thanks to Michal Tichý for his patch.

Tests

In order to have a working development environment, tests are Docker based.

To run the tests, do the following steps

  1. cp .env.example .env
  2. docker-compose up -d
  3. docker-compose exec php ./vendor/bin/phpunit
  4. CTRL+C
  5. docker-compose down

doctrine-oci8's People

Contributors

dependabot[bot] avatar drupol avatar jasonhofer avatar

Watchers

 avatar  avatar

Forkers

chekerm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.