Welcome Guest, Not a member yet? Register   Sign In
Reconnecting to a database after dropping it - simple question
#1

[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




Theme © iAndrew 2016 - Forum software by © MyBB