• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request to the 2 DB at the same time

#1
[eluser]Stell[/eluser]
Hi all.
Htlp me plz.

My code use 2 DB.

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "user";
$db['default']['password'] = "pass";
$db['default']['database'] = "db1";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

$active_group = "CM";
$active_record = TRUE;

$db['CM']['hostname'] = "localhost";
$db['CM']['username'] = "user";
$db['CM']['password'] = "pass";
$db['CM']['database'] = "db2";
$db['CM']['dbdriver'] = "mysql";
$db['CM']['dbprefix'] = "";
$db['CM']['pconnect'] = TRUE;
$db['CM']['db_debug'] = TRUE;
$db['CM']['cache_on'] = FALSE;
$db['CM']['cachedir'] = "";
$db['CM']['char_set'] = "utf8";
$db['CM']['dbcollat'] = "utf8_general_ci";


in construc of my class in model:

Code:
$this->db1= $this->load->database('db1', true);
$this->db2= $this->load->database('db2', true);


Next in this model I use 2 query:

Code:
$q1 = $this->db1->get('table1');
$q2 = $this->db2->get('table2');



and get error:

Code:
A Database Error Occurred

Error Number: 1146

Table 'db2.table2' doesnt exist

SELECT * FROM (`table2`)


but q1 execute. Why q2 faling whith this error?
If swap connection in construct $this->db1 и $this->db2, q2 will exec, and q1 will faling whith error.
What wrong?
Thnx.

#2
[eluser]WanWizard[/eluser]
Shouldn't that be
Code:
$this->db1= $this->load->database('default', true);
$this->db2= $this->load->database('CM', true);

And you can only have one active group in your config, your second assignment overwrites the first.

#3
[eluser]Stell[/eluser]
Sorry? of course
Code:
$active_group = "CM";
fixed already. I del it from config. But I have described problem yet.

#4
[eluser]Stell[/eluser]
Fixed. Thx for all.
Resolution:
Code:
$db['CM']['pconnect'] = TRUE;
wrong. If you use 2 DB and more, you no need establish connection to DB.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.