Desing Help: mutliple databases, different sql |
[eluser]Unknown[/eluser]
Hi All I have a design question I need some assistance with. I'm building an app that needs to query multiple database with different sql statements. The app has a search page where a user will enter a search term and select a database, then depending on the database chosen I must execute a specific sql statement against a specific db. The db connection info and sql statements are all located in a config file. How can I design the app so that I can open a db connection and execute the sql making sure I comply with the framework best practists (should I make a plugin etc). Thanks for any help much appreciated! Cheers Angus
[eluser]abmcr[/eluser]
You can use a group... see as http://ellislab.com/codeigniter/user-gui...ation.html i.e.: $active_group = "test"; Try and send me a feedback! Ciao
[eluser]Randy Casburn[/eluser]
The docs are very clear on how to create multiple simultaneous DB connections. You simply need to implement those methods: $DB1 = $this->load->database('group_one', TRUE); $DB2 = $this->load->database('group_two', TRUE); group_one and group_two corresponds to the database.conf file that contains your DB configurations for each DB group. Your queries could be structured as $sql1 and $sql2: $this->$DB1->query($sql1); OR $this->$DB2->query($sql2); depending on your needs. The docs can be found here: http://ellislab.com/codeigniter/user-gui...cting.html Hope this is helpful. Randy
[eluser]Unknown[/eluser]
Thanks for all your replies I learnt allot. I have another question, the config file that has all the db info and reated sql is kinda like a library, I need user to be able to download updates etc. Having said that is the CI specific config file the best place for the db data. Thanks again! |
Welcome Guest, Not a member yet? Register Sign In |