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

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

问题描述

我有一个项目,我必须与用户指定的数据库连接。我想实现它在一个适当的codeigniter的风格,但我不知道我该如何做那个codeigniter存储数据库凭据在database.php文件是有任何方式使其动态。或者有什么其他方法来实现这一点?我已经google了,但没有发现任何有用的。

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.

推荐答案

p>根据指南,您可以手动传递数据库连接通过 $ 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天全站免登陆