简体   繁体   中英

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?

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.

I'm not sure this will solve all issues, but this packagist library should make Oracle work with Laravel.

Note that OCI8 may still present an issue , however :/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM