Welcome Guest, Not a member yet? Register   Sign In
Forge DB and then Connect to it as default?
#1

[eluser]Unknown[/eluser]
Hi everyone!

I want to let the user create a new DB on the fly, and then connect to it (or any other created previously) and use it as default database for the rest of his session.

Since, I am not using default db connection, I connect to a db, and forging a new database...

Code:
$config['hostname'] = "localhost";
        $config['username'] = "root";
        $config['password'] = "root";
        $config['database'] = 'masterdb';
        $config['dbdriver'] = "mysql";
        $config['dbprefix'] = "";
        $config['pconnect'] = TRUE;
        $config['db_debug'] = TRUE;
        $config['cache_on'] = FALSE;
        $config['cachedir'] = "";
        $config['char_set'] = "utf8";
        $config['dbcollat'] = "utf8_general_ci";

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

        //Forge New Database        
  
        
        $this->load->dbforge();
        $this->dbforge->create_database($new_db_name);
        
        $this->db->close();


and then I want to connect to the one I forged:

Code:
//Connect to it
        
        $config['hostname'] = "localhost";
        $config['username'] = "root";
        $config['password'] = "root";
        $config['database'] = $new_db_name;
        $config['dbdriver'] = "mysql";
        $config['dbprefix'] = "";
        $config['pconnect'] = TRUE;
        $config['db_debug'] = TRUE;
        $config['cache_on'] = FALSE;
        $config['cachedir'] = "";
        $config['char_set'] = "utf8";
        $config['dbcollat'] = "utf8_general_ci";

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

but for some reason, it keeps the connection to the first db...

The point is to use $this->db->select.... etc, without using predefined groups.

Please assist... Sad
#2

[eluser]Unknown[/eluser]
Try this,

$this->db = $this->load->database("lmydb");
$this->load->dbforge();

My prob solved.




Theme © iAndrew 2016 - Forum software by © MyBB