Welcome Guest, Not a member yet? Register   Sign In
Change database [SOLVED]
#1

[eluser]Santiag0[/eluser]
Hi!
I have to change the database which is indicated in the database configuration file.

I try with:
$config['database'] = 'database_name2;
$this->app->load->database($config);

Some idea to change the value of the config/database.php

Thanks!
#2

[eluser]slowgary[/eluser]
In your code above you've left out the second quote. Also, I believe it's
Code:
$this->load->database();

You can also autoload the database using application/config/autoload.php

This is all explained very easily in the user guide.
#3

[eluser]Santiag0[/eluser]
Thanks for reply!
Yes, i do a mistake. But I need change dynamically the configuration default db to make all request to that database. Bacause I have 3 diferente databases with diferente data, and in the login panel you can select user, pass and database. It's clear? Tongue
#4

[eluser]Dam1an[/eluser]
See the Database documentation to see how to load multiple databases

Is that what you're after?
#5

[eluser]Santiag0[/eluser]
Thank you!
I saw the manual but don't try these examples. The final code:

Code:
//Select the database
        $db['hostname'] = "localhost";
        $db['username'] = "root";
        $db['password'] = "supersecret";
        $db['database'] = $this->input->post('db');
        $db['dbdriver'] = "mysql";
        $db['dbprefix'] = "";
        $db['pconnect'] = TRUE;
        $db['db_debug'] = FALSE;
        $db['cache_on'] = FALSE;
        $db['cachedir'] = "";
        $db['char_set'] = "utf8";
        $db['dbcollat'] = "utf8_general_ci";
        $this->load->database($db, TRUE);

So, when I do $this->db->get('table') works, and I don't need to change all my codes, thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB