Welcome Guest, Not a member yet? Register   Sign In
Runtime database connection details setup
#2

[eluser]theprodigy[/eluser]
According to the database section of the user_guide
Quote:To connect manually to a desired database you can pass an array of values:
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

$this->load->database($config);

Just fill the config array with the necessary values at runtime, then pass it into the load->database call.

To connect to multiple databases, just set some variables equal to the load->database call, and pass in TRUE for the second parameter (it's listed in the same section of the user guide)
Quote:If you need to connect to more than one database simultaneously you can do so as follows:
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

Use these two in techniques together, and come up with something like:
Code:
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

$DB1 = $this->load->database($config, TRUE);

$config['username'] = "myusername_2";
$config['password'] = "mypassword_2";
$config['database'] = "mydatabase_2";

$DB2 = $this->load->database($config, TRUE);

If you need to be connected to both databases at the same time, make sure to leave pconnect set to false, otherwise you may run into issues.


Messages In This Thread
Runtime database connection details setup - by El Forum - 02-13-2010, 11:13 AM
Runtime database connection details setup - by El Forum - 02-13-2010, 07:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB