Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Oracle: CodeIgniter vs Laravel

I have been looking for a PHP framework for a project I'm currently working on. One of the primary requirements is an easy way to interact with our database. Initially this must be Oracle, but there is a possibility of switching to a different database back-end in the future. Hence, I want to be able to write code that is as database agnostic as possible.

I've initially been leaning toward CodeIgniter, mainly because of its Oracle support (it includes drivers that are written to take advantage of Oracle's own OCI8 drivers).

Laravel is another alternative that I've considered. It seems to be a popular option, even with some previous CodeIgniter users (for example, see this answer). However, its Oracle support seems very limited; as far as I can tell Laravel uses PDO extensively, but PDO for Oracle is experimental and not recommended.

Is there an easy way that I can connect to Oracle using Laravel in a database agnostic way?

like image 726
FixMaker Avatar asked Sep 18 '13 19:09

FixMaker


1 Answers

After researching the link provided by fideloper it looks like some helpful coder(s) have continued to develop a PDO user-space driver for Oracle that takes advantage of the native OCI8 PHP driver functions.

According to this website this can be installed in Laravel by using composer:

Add yajra/laravel-oci8 as a requirement to composer.json:

{
    "require": {
        "yajra/laravel-oci8": "*"
    }
}

And then run:

composer update

Once Composer has installed or updated your packages you need to register the service provider. Open up app/config/app.php and find the providers key and add:

yajra\Oci8\Oci8ServiceProvider

Finally you need to setup a valid database configuration using the driver "pdo-via-oci8". Configure your connection as usual with:

'connection-name' => array(
    'host' => 'something',
    'port' => 'something',
    'username' => 'something',
    'password' => 'something',
    'charset' => 'something',
    'prefix' => 'something', )

Then Laravel can access Oracle in a database-agnostic way using Eloquent etc. I've given this some basic testing it seems to work well.

like image 194
FixMaker Avatar answered Sep 21 '22 00:09

FixMaker