Skip to content

WARNING You're browsing the documentation for an old version of LARAVEL-OCI8. Consider upgrading your project to laravel-oci8 11.0.

Stand Alone Usage

This documentation demonstrates how to use the package outside of Laravel.

  • add "yajra/laravel-oci8": "5.3.*" on your composer then run composer install
  • create database.php and add the code below
require 'vendor/autoload.php';
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 session variables
$sessionVars = [
// Like Postgres, Oracle allows the concept of "schema"
if (isset($config['schema']))
$sessionVars['CURRENT_SCHEMA'] = $config['schema'];
return $db;
'driver' => 'oracle',
'host' => '',
'database' => 'xe',
'username' => 'user',
'password' => 'password',
'prefix' => '',
'port' => 1521

Set the event dispatcher used by Eloquent models (Optional).

use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)

Now we can start working with database tables just like we would if we were using Laravel!

require 'database.php';
// Create the User model
class User extends Illuminate\Database\Eloquent\Model {
public $timestamps = false;
// Grab a user with an id of 1
$user = User::find(1);
echo $user->toJson(); die();