连接到 Oracle:CodeIgniter 与 Laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18880719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:26:52  来源:igfitidea点击:

Connecting to Oracle: CodeIgniter vs Laravel

phporaclecodeigniterlaravel

提问by FixMaker

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.

我一直在为我目前正在从事的项目寻找 PHP 框架。主要要求之一是与我们的数据库交互的简单方法。最初这必须是 Oracle,但将来有可能切换到不同的数据库后端。因此,我希望能够编写尽可能与数据库无关的代码。

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).

我最初倾向于使用 CodeIgniter,主要是因为它的 Oracle 支持(它包括为利用 Oracle 自己的 OCI8 驱动程序而编写的驱动程序)。

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.

Laravel 是我考虑过的另一种选择。它似乎是一个流行的选项,即使是一些以前的 CodeIgniter 用户(例如,请参阅此答案)。但是,它的 Oracle 支持似乎非常有限;据我所知,Laravel 广泛使用 PDO,但 PDO for Oracle 是实验性的,不推荐使用

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

有没有一种简单的方法可以以数据库不可知的方式使用 Laravel 连接到 Oracle?

采纳答案by fideloper

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

我不确定这会解决所有问题,但是这个 packagist 库应该可以让 Oracle 与 Laravel 一起工作。

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

请注意,OCI8 可能仍然存在问题,但是:/

回答by FixMaker

After researching the link provided by fideloperit 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.

在研究了fideloper提供的链接后,看起来一些有用的编码人员继续为 Oracle 开发 PDO 用户空间驱动程序,该驱动程序利用了本机 OCI8 PHP 驱动程序功能。

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

根据这个网站,这可以通过使用 composer 安装在 Laravel 中:

Add yajra/laravel-oci8as 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', )

yajra/laravel-oci8作为要求添加到composer.json

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

然后运行:

composer update

Composer 安装或更新您的软件包后,您需要注册服务提供商。打开 app/config/app.php 并找到 providers 键并添加:

yajra\Oci8\Oci8ServiceProvider

最后,您需要使用驱动程序“pdo-via-oci8”设置有效的数据库配置。像往常一样配置您的连接:

'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.

然后 Laravel 可以使用 Eloquent 等以与数据库无关的方式访问 Oracle。我已经对此进行了一些基本测试,它似乎运行良好。