如何在codeigniter中连接用户指定的数据库 [英] How to connect with user specified database in codeigniter

查看:25
本文介绍了如何在codeigniter中连接用户指定的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我必须在其中连接用户指定的数据库.我想以适当的 codeigniter 风格实现它,但我不知道我该怎么做,codeigniter 将数据库凭据存储在 database.php 文件中,有什么方法可以使其动态化.或者有没有其他方法可以实现这一目标?我用谷歌搜索了它,但没有找到任何有用的东西.任何帮助和建议将不胜感激.

I have a project in which i have to connect with user specified database. I want to implement it in a proper codeigniter's style but i dont know how can i do that codeigniter stores database credentials in a database.php file is there any way to make it dynamic. Or is there any other approach for achieving this? I have googled it but did not find anything helpful. Any help and suggestion would be appreciated.

更新:
该项目是关于报告的.我有一个表单,我在其中获取了数据库登录凭据,然后生成了有关其数据库的报告,一切都将在运行时完成.

UPDATE:
The project is about reporting. I have a form in which i got the database login credentials and then generate the report about their database everything would be done on runtime.

推荐答案

根据 指南,你可以通过$this->load->model的第三个参数手动传递数据库连接设置:

According to the guide, you can manually pass database connectivity settings via the third parameter of $this->load->model:

$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;

$this->load->model('Model_name', '', $config);
// or as gorelative notes, to access multiple databases:
$DB2 = $this->load->database($config, TRUE);

这篇关于如何在codeigniter中连接用户指定的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆