简体   繁体   中英

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. I have data in an Oracle database retrieved via PDO and a MySQL db which is using the "built in" configuration for CI. 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)

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

Is this pretty much the way it is with all php frameworks? 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.

EDIT: For CI, I think this is the answer:

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.

-- these are assuming the built in drivers for CI. this does not answer then you have multiple databases and non-CI drivers

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 would only know of the Oracle database, and queries to the MySQL instance would have to pass through the Oracle instance. There are details on the setup for a database link to a MySQL instance in this article .

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