PHP:CodeIgniter;管理两个数据库连接;可变数据库参数 [英] PHP: CodeIgniter; Managing two db connections; variable database parameters
问题描述
我开始使用CI进行编码,并且在以下方面遇到一些问题:我需要一个控制器,该控制器将从给定的服务器登录密码返回数据库列表以及每个数据库中的表。
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.
在阅读用户指南后,我已经找到了所需的一切,但我仍然很难设法完成这项工作。我相信我不能依靠database.php配置(多个组),因为我的控制者必须接受任何给定的服务器登录密码。
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);
我也不确定:
$this->load->dbutil();
用户指南指出:
Important: In order to initialize the Utility class, your database driver must
already be running, since the utilities class relies on it.
因此,例如,如果我同时加载了两个同时具有不同驱动程序的数据库,我将如何更改$ this-> load-> dbutil();加载一个想要的ID?
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?
推荐答案
在以下位置找到了详细的帮助: www.codeigniter.com/forums/viewthread/202659
Found detailed help in: www.codeigniter.com/forums/viewthread/202659
这篇关于PHP:CodeIgniter;管理两个数据库连接;可变数据库参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!