Welcome Guest, Not a member yet? Register   Sign In
automatically connecting two databases
#1

[eluser]eugenia08[/eluser]
how can i automatically connecting two databases, and if the only way to do that is manually where i must write the
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
and group_one and group_two are the name of the data base or the name that i put in the autoload archive when i define the databases: db[default][bla bla bla]
and the other is db[the_other][bla bla bla], please , i dont understand,
eugenia
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

There's no built-in way to connect to multiple databases automatically. You'd need to do that from within your controller (although there are other ways). In your controller constructor, you can do something like this:

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

Then you can call upon them with $this->DB1 and $this->DB2 respectively.
#3

[eluser]eugenia08[/eluser]
thank you very much for your response! but i have only two more question : what is group_one and group_two? they are the name of the data bases? or are the name that i put when i define the dbs in the config/database.php: db[default][hostname]="localhost" and db[second][hostname]="localhost", in this case the $active_group was which one?
eugenia
#4

[eluser]TheFuzzy0ne[/eluser]
No, they are aliases so you (and CodeIgniter) can tell the difference between them. You can name your database groups Fred and Bob for all CodeIgniter cares. Whatever is easiest for you.

Code:
$db['bob']['hostname'] = "localhost";
$db['bob']['username'] = "user1";
$db['bob']['password'] = "p455w0rd";
$db['bob']['database'] = "my_db";
$db['bob']['dbdriver'] = "mysql";
$db['bob']['dbprefix'] = "";
$db['bob']['pconnect'] = TRUE;
$db['bob']['db_debug'] = TRUE;
$db['bob']['cache_on'] = FALSE;
$db['bob']['cachedir'] = "";
$db['bob']['char_set'] = "utf8";
$db['bob']['dbcollat'] = "utf8_general_ci";

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

It doesn't matter what you call it. Smile
#5

[eluser]eugenia08[/eluser]
ok, i understand now, really really thank you very much!!!! Wink
#6

[eluser]eugenia08[/eluser]
hello again, a have a little problem now, i need to do some operations at the same time in my two data bases (db1 and db2) but i don't know how to start the transaction because isn't ok to do something like: $this->db2->trans_start();
or $this->db1->trans_start();
$this->db2->trans_start();
etc etc, so i need something like sqlrelay, but i don't know how to implement this in CI,
thank you for your time,
eugenia




Theme © iAndrew 2016 - Forum software by © MyBB