PHP: CodeIgniter; Managing two db connections; variable database parameters

本秂侑毒 提交于 2019-12-13 07:01:02

问题


i’m starting to code in CI and i have some problems with the following matter: I need a controller that will return a list of databases from a given server-login-pass and the tables in each database.

Reading the user guide i’ve found everything i need, but still i have trouble managing to make this work. I believe i cant rely on the database.php config (multiple groups) since my controler has to accept any given server-login-pass.

Going straight to the point, i’ve tried this basic code and many variants without luck ;

$db1 = $this->load->database('mysql://flux:foo@localhost');
$db2 = $this->load->database('mysql://flux:foo@localhost/mydb');

$this->load->dbutil();

$db_list = $db1->list_databases();
print_r($db_list);

$db_tables = $db2->db->list_tables();
print_r($db_tables);

Also i'm not sure about:

$this->load->dbutil();

The user guide states:

Important:  In order to initialize the Utility class, your database driver must 
already be running, since the utilities class relies on it.

So if for example i had two simultaneous databases loaded, both with diferent drivers, how would i change $this->load->dbutil(); to load in the one id want?


回答1:


Found detailed help in: www.codeigniter.com/forums/viewthread/202659



来源:https://stackoverflow.com/questions/7867591/php-codeigniter-managing-two-db-connections-variable-database-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!