Welcome Guest, Not a member yet? Register   Sign In
SQL database connection errors suppressed - why?
#1

[eluser]Unknown[/eluser]
I was really wondering why, after I tried connecting to a database using the CodeIgniter's functions, I just got a blank web page. No errors anywhere - not in CodeIgniter's, PHP's or Apache's logs. Digging further into CodeIgniter's source code, I was finally able to track down this line:

@mysql_pconnect($this->hostname, $this->username, $this->password);

So all connection errors are suppressed, and there's no way I could know what's wrong. Taking out the @-sign obviously helped. Shouldn't this definitely be changed?
#2

[eluser]Mike Ryan[/eluser]
Hi,

The error checking is handled "above" the line you quoted:

Code:
//file system/database/DB_driver.php
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this->db_pconnect();

// No connection resource?  Throw an error
if ( ! $this->conn_id)
{
    log_message('error', 'Unable to connect to the database');

    if ($this->db_debug)
    {
        $this->display_error('db_unable_to_connect');
    }
    return FALSE;
}

So, although the @ preceding the mysql_pconnect function call will suppress any errors, it will still return false and cause the error to be logged (albeit with limited information) by DB_Driver.php.

You definitely should have seen something in CI's log - are you sure CI is able to write to log files, and has $config['log_threshold'] > 0 in config.php?




Theme © iAndrew 2016 - Forum software by © MyBB