CodeIgniter Forums
Reconnecting to a database after dropping it - simple question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Reconnecting to a database after dropping it - simple question (/showthread.php?tid=3386)



Reconnecting to a database after dropping it - simple question - El Forum - 09-27-2007

[eluser]LeePR[/eluser]
Hey guys,

I'm using the database utilities class to drop and recreate a database. Here are the three relevant methods in my UnitTestUtil class:

Code:
/** Drop the database. */
public function dropDatabase($database = "rsfs")     {
    if (!$this->CI->dbutil->drop_database($database)) {
        throw new RSFSException("'$database' " . $this->CI->lang->line('database_not_dropped'));
    }
}

/** Create the database. */
public function createDatabase($database = "rsfs") {
    if (!$this->CI->dbutil->create_database($database)) {
        throw new RSFSException("'$database' " . $this->CI->lang->line('database_not_created'));
    }
}


/** Load default data.*/
public function loadDefaultData() {
    $this->execute($this->strSqlPath . $this->strDefaultData);
    // ^ in a nutshell, this method just passes it to $this->CI-db->query().
}

All three methods work perfectly when run on their own however when I try to do the following:

Code:
$utils->dropDatabase();
$utils->createDatabase();
$this->CI->load->database(); // Doesn't seem to help.
$utils->loadDefaultData();

I get the following error message
Quote:Error Number: 1046

No database selected

I've tried everything - how can I reconnect to the newly created database? It's the same database that's in the config file - it connects with a call to `$utils->loadDefaultData()` the first time around, but not after dropping and recreating it.

Thanks in advance,
LeePR