1. Go to this page and download the library: Download yawaweb/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/ */
yawaweb / yii2-oci8 example snippets
$config = [
...
'components' => [
...
'db' =>
return [
'class' => 'yawaweb\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';
-- ATTENSION: A 'NLS_COMP=LINGUISTIC' option is slow down queries;
-- execute immediate 'alter session set NLS_COMP=LINGUISTIC';
end;
SQL;
$event->sender->createCommand($q)->execute();
}
];
$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' => 'yawaweb\yii2oci8\CachedSchema',
// Optional, dafault is 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) {
//Cache everything but the EMP table from HR and SCOTT schemas
return $tableName != 'EMP';
}
],
...