PHP code example of pdynarowski / yii2-oci8

1. Go to this page and download the library: Download pdynarowski/yii2-oci8 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pdynarowski / yii2-oci8 example snippets


$config = [
    ...
    'components' => [
        ...
        'db' => 

return [
'class' => 'pdynarowski\yii2oci8\Oci8Connection',
        'dsn' => 'oci:dbname=//192.168.0.1:1521/instance_name;charset=UTF8',
        'username' => 'username',
        'password' => 'password',
        'enableSchemaCache' => false,
        'on afterOpen' => function($event) {
            $event->sender->createCommand("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")->execute();
        },
        'schemaCacheDuration' => 0,
        'attributes' => [ PDO::ATTR_PERSISTENT => true ],
        'on afterOpen' => function($event)
        {
            /* @var $schema \neconix\yii2oci8\CachedSchema */
            $event->sender->createCommand("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")->execute();
            $schema = $event->sender->getSchema();
            $schema->schemaCacheDuration = 0; // 0 - never expire
            if (!$schema->isCached) {
                //Rebuild schema cache
                $schema->buildSchemaCache();
            }
        },
        //Defining a cache schema component
        'cachedSchema' => [
            'class' => 'pdynarowski\yii2oci8\CachedSchema',
            'schemaCacheDuration'=>0, //60*60,
        ],
];

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

$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

    ...
    //Disabling Yii2 schema cache
    'enableSchemaCache' => false
    
    //Defining a cache schema component
    'cachedSchema' => [
        'class' => 'pdynarowski\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';
        }
    ],
    ...

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

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

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