/** * Register the service provider. * * @return void */ public function register() { $this->app['db']->extend('oracle', function ($config) { $connector = new Connector(); $connection = $connector->connect($config); $db = new Oci8Connection($connection, $config["database"], $config["prefix"]); // set oracle session variables $sessionVars = ['NLS_TIME_FORMAT' => 'HH24:MI:SS', 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', 'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM', 'NLS_NUMERIC_CHARACTERS' => '.,']; // Like Postgres, Oracle allows the concept of "schema" if (isset($config['schema'])) { $sessionVars['CURRENT_SCHEMA'] = $config['schema']; } $db->setSessionVars($sessionVars); return $db; }); }
/** * Register the service provider. * * @return void */ public function register() { if (file_exists(config_path('oracle.php'))) { $this->mergeConfigFrom(config_path('oracle.php'), 'database.connections'); } else { $this->mergeConfigFrom(__DIR__ . '/../config/oracle.php', 'database.connections'); } $this->app['db']->extend('oracle', function ($config) { $connector = new Connector(); $connection = $connector->connect($config); $db = new Oci8Connection($connection, $config["database"], $config["prefix"], $config); if (!empty($config['skip_session_vars'])) { return $db; } // set oracle session variables $sessionVars = ['NLS_TIME_FORMAT' => 'HH24:MI:SS', 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', 'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM', 'NLS_NUMERIC_CHARACTERS' => '.,']; // Like Postgres, Oracle allows the concept of "schema" if (isset($config['schema'])) { $sessionVars['CURRENT_SCHEMA'] = $config['schema']; } $db->setSessionVars($sessionVars); return $db; }); }
<?php require 'vendor/autoload.php'; ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(-1); use Illuminate\Database\Capsule\Manager as Capsule; use yajra\Oci8\Connectors\OracleConnector; use yajra\Oci8\Oci8Connection; $capsule = new Capsule(); $manager = $capsule->getDatabaseManager(); $manager->extend('oracle', function ($config) { $connector = new OracleConnector(); $connection = $connector->connect($config); $db = new Oci8Connection($connection, $config["database"], $config["prefix"]); // set oracle date format to match PHP's date $db->setDateFormat('YYYY-MM-DD HH24:MI:SS'); return $db; }); $username = $params['username']; $password = $params['password']; $host = $params['host']; $database = $params['database']; $capsule->addConnection(array('driver' => 'oracle', 'host' => $host, 'database' => $database, 'username' => $username, 'password' => $password, 'prefix' => '', 'port' => 1521)); $capsule->bootEloquent();