PHP:代码点火器;管理两个数据库连接;可变数据库参数
我开始在 CI 中编码,并且在以下问题上遇到一些问题:我需要一个控制器,它将从给定的服务器登录通道和每个数据库中的表返回数据库列表。
阅读用户指南,我找到了我需要的一切,但我仍然无法成功完成这项工作。我相信我不能依赖database.php配置(多个组),因为我的控制器必须接受任何给定的服务器登录通行证。
开门见山,我已经尝试了这个基本代码和许多变体,但没有运气;
$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?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到详细帮助:www.codeigniter.com/forums/viewthread/202659
Found detailed help in: www.codeigniter.com/forums/viewthread/202659