简体   繁体   English

您如何在CodeIgniter中连接到MySQL和Oracle?

[英]How do you connect to MySQL and Oracle in CodeIgniter?

I am confused as to how to configure CodeIgniter to use more than one database. 对于如何配置CodeIgniter以使用多个数据库,我感到困惑。 I have data in an Oracle database retrieved via PDO and a MySQL db which is using the "built in" configuration for CI. 我在通过PDO和MySQL数据库(使用CI的“内置”配置)检索的Oracle数据库中有数据。 From what I can see, I only have the main configuration file that allows me to config one database (in this case the MySQL one) 从我所看到的,我只有一个主配置文件,它允许我配置一个数据库(在本例中为MySQL数据库)

How do I get data back from more than one database in the same webpage/view? 如何从同一网页/视图中的多个数据库取回数据? Say I have MySQL built in to the main config page. 假设我在主配置页面中内置了MySQL。 Do I just make another connection in my controller (do I do it the "regular" old non-framework way), fetch my array and send that array to the view? 我是否只是在控制器中建立另一个连接(以“常规的”旧的非框架方式进行连接),获取数组并将该数组发送到视图? In other words my main configured database can use the built in CI activerecord type queries but my other databases can't take advantage of that? 换句话说,我的主要配置数据库可以使用内置的CI activerecord类型查询,但是我的其他数据库不能利用它吗?

Is this pretty much the way it is with all php frameworks? 这几乎是所有php框架的方式吗? YOu end up making connections in your controller, the old fashioned way, and sending data to the view? 您最终会以老式的方式在您的控制器中建立连接并将数据发送到视图吗?

Thanks. 谢谢。

EDIT: I guess I'm saying the model for the second database ends up in the controller...which is bad isn't it? 编辑:我想我是说第二个数据库的模型最终出现在控制器中……这很糟糕,不是吗?

EDIT: Oracle was just an example. 编辑:甲骨文只是一个例子。 It could be any database CI can natively talk to. CI可以与之进行本地通信的任何数据库。

EDIT: For CI, I think this is the answer: 编辑:对于CI,我认为这是答案:

http://codeigniter.com/user_guide/database/connecting.html http://codeigniter.com/user_guide/database/connecting.html

though I'm not sure how to use it. 虽然我不确定如何使用它。

EDIT: Found it here too: http://www.gotphp.com/codeigniter-multiple-database-support/5468/ better. 编辑:也在这里找到它: http : //www.gotphp.com/codeigniter-multiple-database-support/5468/更好。

-- these are assuming the built in drivers for CI. -这些都是假定CI的内置驱动程序。 this does not answer then you have multiple databases and non-CI drivers 这不能回答,那么您有多个数据库和非CI驱动程序

You could consolidate the connection info for CodeIgniter to only use the Oracle database, because Oracle has functionality called a "database link" to allow you to connect to other databases (including different vendors like MySQL). 您可以合并CodeIgniter的连接信息,使其仅使用Oracle数据库,因为Oracle具有称为“数据库链接”的功能,允许您连接到其他数据库(包括MySQL等不同的供应商)。 CodeIgniter would only know of the Oracle database, and queries to the MySQL instance would have to pass through the Oracle instance. CodeIgniter只知道Oracle数据库,而对MySQL实例的查询将必须通过Oracle实例。 There are details on the setup for a database link to a MySQL instance in this article . 本文中有有关到MySQL实例的数据库链接的设置的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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