Home

Awesome

Laravel Oracle Database Package

OracleDB (updated for Laravel 11)

<a href="https://github.com/jfelder/Laravel-OracleDB/actions"><img src="https://github.com/jfelder/Laravel-OracleDB/workflows/tests/badge.svg" alt="Build Status"></a> <a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/dt/jfelder/oracledb" alt="Total Downloads"></a> <a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/v/jfelder/oracledb" alt="Latest Stable Version"></a> <a href="https://packagist.org/packages/jfelder/oracledb"><img src="https://img.shields.io/packagist/l/jfelder/oracledb" alt="License"></a>

OracleDB is an Oracle Database Driver package for Laravel Framework - thanks @taylorotwell. OracleDB is an extension of Illuminate/Database that uses the OCI8 Functions wrapped into the PDO namespace.

Please report any bugs you may find.

Installation

With Composer:

composer require jfelder/oracledb

During this command, Laravel's "Auto-Discovery" feature should automatically register OracleDB's service provider.

Next, publish OracleDB's configuration file using the vendor:publish Artisan command. This will copy OracleDB's configuration file to config/oracledb.php in your project.

php artisan vendor:publish --tag=oracledb-config

To finish the installation, set your environment variables (typically in your .env file) to the corresponding env variables used in config/oracledb.php: such as DB_HOST, DB_USERNAME, etc.

Double Check Your Date Format Config The date_format config powers all date column casting to/from Carbon and defaults to Y-m-d H:i:s, so it is imperative to set the DB_DATE_FORMAT env var if your db stringifies dates a different way, ie d-M-y H:i:s. This affects all read/write operations of any Eloquent model with date fields and any Query Builder queries that utilize a Carbon instance.

Basic Usage

The configuration file for this package is located at config/oracledb.php. In this file, you define all of your oracle database connections. If you need to make more than one connection, just copy the example one. If you want to make one of these connections the default connection, enter the name you gave the connection into the "Default Database Connection Name" section in config/database.php.

Once you have configured the OracleDB database connection(s), you may run queries using the DB facade as normal.

Note: The default driver, 'oci8', makes OracleDB use the OCI8 Functions under the hood. If you want to use PDO_OCI instead, change the driver value to 'pdo' in the config/oracledb.php file.

$results = DB::select('select * from users where id = ?', [1]);

The above statement assumes you have set the default connection to be the oracle connection you setup in config/database.php file and will always return an array of results.

$results = DB::connection('oracle')->select('select * from users where id = ?', [1]);

Just like the built-in database drivers, you can use the connection method to access the oracle database(s) you setup in config/oracledb.php file.

Inserting Records Into A Table With An Auto-Incrementing ID

$id = DB::connection('oracle')->table('users')->insertGetId(
    ['email' => 'john@example.com', 'votes' => 0], 'userid'
);

Note: When using the insertGetId method, you can specify the auto-incrementing column name as the second parameter in insertGetId function. It will default to "id" if not specified.

See Laravel Database Basic Docs for more information.

Unimplemented Features

Some of the features available in the first-party Laravel database drivers are not implemented in this package. Pull requests are welcome for implementing any of these features, or for expanding this list if you find any unimplemented features not already listed.

Query Builder

Eloquent

Schema Builder

License

Licensed under the MIT License.