Welcome Guest, Not a member yet? Register   Sign In
Test for database connection success
#6

[eluser]Randy Casburn[/eluser]
Something like this should work. Override the mysql_driver class with this. You'll likely need to do the same with the persistent connect method as well.

Use the "Catch" to do what ever you want to do with the failed exception.

Code:
class MY_DB_mysql_driver extends CI_DB {
    /**
     * Non-persistent database connection
     *
     * @access    private called by the base class
     * @return    resource
     */    
    function db_connect()
    {
        try
        {
            return my_db_connect();          
        }
        catch(Exception $e)
        {
            return 'Caught exception: ',  $e->getMessage(), "\n";
        }
    }        

    function my_db_connect()
    {
        $conn_id = @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
        
        if (! $conn_id )
        {
            throw new Exception('DB Connection Failed.');
        }
        else
        {
            return $conn_id;
        }
        return
    }
}

Randy


Messages In This Thread
Test for database connection success - by El Forum - 08-01-2008, 08:57 PM
Test for database connection success - by El Forum - 08-02-2008, 01:20 PM
Test for database connection success - by El Forum - 08-02-2008, 02:36 PM
Test for database connection success - by El Forum - 08-02-2008, 05:59 PM
Test for database connection success - by El Forum - 08-02-2008, 06:04 PM
Test for database connection success - by El Forum - 08-02-2008, 08:14 PM
Test for database connection success - by El Forum - 11-02-2008, 09:14 AM
Test for database connection success - by El Forum - 11-02-2008, 09:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB