Welcome Guest, Not a member yet? Register   Sign In
Database connection run time
#1

[eluser]Amit Patel[/eluser]
Hello All,

I want to connect database at runtime . It is working when i define database info in database.php and connect it using $this->load->database('group_name',TRUE) where group name is define in config/database.php . But when i create connection at runtime using (as help is givne in datbase class but it's not working)
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";


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


the database is not connected and use old database so how can i connect the database at run time because i have stored the mysql info in the database table so i have to connect database runtime i can't define in database.php....


so how can i do this . Please help me.
#2

[eluser]Clooner[/eluser]
Add 'database' to the library array in the autoload file in your 'application/config' directory.
#3

[eluser]Amit Patel[/eluser]
It is already added in autoload file like

Code:
$autoload['libraries'] = array("database", "session", "validation", "user_agent","Template");

But it's now working....




Theme © iAndrew 2016 - Forum software by © MyBB