Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...