2017 © Pedro Peláez
 

library yii2-oci8

Yii2 extension which uses well written pdo-via-oci8 package for standard PHP Oracle functions (OCI8)

image

neconix/yii2-oci8

Yii2 extension which uses well written pdo-via-oci8 package for standard PHP Oracle functions (OCI8)

  • Sunday, April 16, 2017
  • by Neconix
  • Repository
  • 1 Watchers
  • 2 Stars
  • 888 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 3 Versions
  • 12 % Grown

The README.md

Yii2-Oci8

Yii2 OCI8 extension which uses well written yajra/pdo-via-oci8 with optional full table schema caching. Supported PHP7., (*1)

Supported - Yii 2.x; - yajra/pdo-via-oci8 1.x; - >= PHP 5.4; - >= PHP 7.0., (*2)

Installation, (*3)

Add to your composer.json file:, (*4)

   "require": {
     "neconix/yii2-oci8": "1.*"
   }

And then run composer update., (*5)

Yii2 configuration example for an Oracle database, (*6)

Yii2 configuration:, (*7)

$config = [
    ...
    'components' => [
        ...
        'db' => require(__DIR__ . '/db.php'),
        ...
    ]
];

Database configuration in db.php:, (*8)

return [
    'class' => 'neconix\yii2oci8\Oci8Connection',
    'dsn' => 'oci:dbname=//192.168.0.1:1521/db.local;charset=AL32UTF8;',
    'username' => 'user',
    'password' => 'pass',
    'attributes' => [ PDO::ATTR_PERSISTENT => true ],
    'enableSchemaCache' => true, //Oracle dictionaries is too slow :(, enable caching
    'schemaCacheDuration' => 60 * 60, //1 hour
    'on afterOpen' => function($event) {

    /* A session configuration example */
        $q = <<<SQL
begin
  execute immediate 'alter session set NLS_SORT=BINARY_CI';
  execute immediate 'alter session set NLS_TERRITORY=AMERICA';
end;
SQL;
        $event->sender->createCommand($q)->execute();
    }
];

Example, (*9)

Feel free to use Yii2 ActiveRecord methods:, (*10)

$cars = Car::find()->where(['YEAR' => '1939'])->indexBy('ID')->all();

Getting a raw database handler and working with it:, (*11)

$dbh = Yii::$app->db->getDbh();
$stmt = oci_parse($dbh, "select * from DEPARTMENTS where NAME = :name");
$name = 'NYPD';
oci_bind_by_name($stmt, ':name', $name);
oci_execute($stmt);
...
//fetching result

Caching features, (*12)

To enable caching for all tables in a schema add lines below in a database connection configuration db.php:, (*13)

    ...
    //Disabling Yii2 schema cache
    'enableSchemaCache' => false

    //Defining a cache schema component
    'cachedSchema' => [
        'class' => 'neconix\yii2oci8\CachedSchema',
        // Optional, default is the current connection schema.
        'cachingSchemas' => ['HR', 'SCOTT'],
        // Optional. This callback must return `true` for a table name if it need to be cached.
        'tableNameFilter' => function ($tableName, $schemaName) {
            //Cache everything but the EMP table from HR and SCOTT schemas
            return $tableName != 'EMP';
        }
    ],
    ...

Table schemas saves to the default Yii2 cache component. To build schema cache after a connection opens:, (*14)

    'on afterOpen' => function($event) 
    {
        $event->sender->createCommand($q)->execute();

        /* @var $schema \neconix\yii2oci8\CachedSchema */
        $schema = $event->sender->getSchema();

        if (!$schema->isCached)
            //Rebuild schema cache
            $schema->buildSchemaCache();
    },

The Versions

16/04 2017

dev-master

9999999-dev

Yii2 extension which uses well written pdo-via-oci8 package for standard PHP Oracle functions (OCI8)

  Sources   Download

MIT

The Requires

 

by Avatar Neconix

database yii2 oci8 oracle

15/03 2017

1.1

1.1.0.0

Yii2 extension which uses well written pdo-via-oci8 package for standard PHP Oracle functions (OCI8)

  Sources   Download

MIT

The Requires

 

by Avatar Neconix

database yii2 oci8 oracle

20/09 2016

1.0.0

1.0.0.0

Yii2 extension which uses well written pdo-via-oci8 package for standard PHP Oracle functions (OCI8)

  Sources   Download

MIT

The Requires

 

by Avatar Neconix

database yii2 oci8 oracle