Welcome Guest, Not a member yet? Register   Sign In
Which database will the system choose to insert the record ??
#1

[eluser]cinewbie81[/eluser]
The following is my database config file setting:

Code:
$active_group = "db1";
$db['db1']['hostname'] = "localhost";
$db['db1']['username'] = "root";
$db['db1']['password'] = "password;
$db['db1']['database'] = "db1";
$db['db1']['dbdriver'] = "mysql";
$db['db1']['dbprefix'] = "";
$db['db1']['active_r'] = TRUE;
$db['db1']['pconnect'] = TRUE;
$db['db1']['db_debug'] = TRUE;
$db['db1']['cache_on'] = FALSE;
$db['db1']['cachedir'] = "";


$active_group = "db2";
$db['db2']['hostname'] = "localhost";
$db['db2']['username'] = "root";
$db['db2']['password'] = "password;
$db['db2']['database'] = "db2";
$db['db2']['dbdriver'] = "mysql";
$db['db2']['dbprefix'] = "";
$db['db2']['active_r'] = TRUE;
$db['db2']['pconnect'] = TRUE;
$db['db2']['db_debug'] = TRUE;
$db['db2']['cache_on'] = FALSE;
$db['db2']['cachedir'] = "";

And here's my code:

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

$this->db->insert('mytable', $data);


Let's assume that both db1 and db2 have the exactly the same database structure.
My question is when i call $this->db->insert('mytable', $data) statement, the system will save the data in db1 or db2? How can i manually control which db i want the data to be inserted ? Anyone ?
#2

[eluser]xwero[/eluser]
Instead of $this->db you have to do $DB1->insert or $DB2->insert.
#3

[eluser]cinewbie81[/eluser]
Opps .. that's the easy one .. how could i don't know that ..
Looks like the workload is up to my head now .. it's time to take a rest ..
many thanks xwero !!




Theme © iAndrew 2016 - Forum software by © MyBB