Welcome Guest, Not a member yet? Register   Sign In
CI_DB_driver Bug
#1

[eluser]bcdennis[/eluser]
Code:
// If an existing DB connection resource is supplied
        // there is no need to connect and select the database
        if (is_resource($this->conn_id) OR is_object($this->conn_id))
        {
            return TRUE;
        }

I don't think the 'OR is_object($this->conn_id)' part of the sentinel should be there. The connection could still be invalid even if it's an object. In my application I have to fork some child processes (which closes any resources upon exiting), and issuing a $db->initialize() would always re-instate the connection. However, in 1.6.3 with this new sentinel, after forking any database queries are failing with the
Code:
Error Number: 2006

MySQL server has gone away
issue.
#2

[eluser]apolinux[/eluser]
I had the same problem. I'm running a standalone application which forks, and I try to connect and then query, but just in the query got

MySQL server has gone away

Is there any solution, experts?
#3

[eluser]solepixel[/eluser]
I get this same error on our GoDaddy server. Not really having a problem on any other servers (Mosso/Rackspace, or LiquidWeb). I tried commenting out the code in question, but it didn't seem to help. I would like to know another solution if there is one, although, I'm pretty sure it's a server configuration issue.
#4

[eluser]WanWizard[/eluser]
The initialize() method is called before running a query in the simple_query() method:
Code:
if ( ! $this->conn_id)
{
    $this->initialize();
}

If some other/external event has closed the connection to your database (for whatever reason), CI is not aware of this unless this event has called $this->db->close().

My guess is therefore that $this->conn_id doesn't evaluate to false, so the initialize() method isn't even called. You only get an error when you try to execute your query, and the query library used detects that the resource that is stored in $this->conn_id when the database connection is made by CI is no longer valid.

Since you can not extend DB_driver, maybe modifying the code to:
Code:
if ( ! $this->conn_id OR ! is_resource( $this->conn_id) )
{
    $this->conn_id = FALSE;
    $this->initialize();
}
will fix it.

edit: probably not. It will still be a resource as far as PHP is concerned, the first database call that tries to use it will throw an error.

The best way off course is to prevent this race condition from happening, and make sure none of your code closes the database connection. It's an indication of bad coding practice, housekeeping should be at the end of script execution.
#5

[eluser]WanWizard[/eluser]
Note, if you use persistent database connections, those resources will not be cleaned up by a terminating script. Did you configure your database for persistent connections in the config file?
If so, maybe your hoster has configured the database engine not to allow persistent connections. In which case this problem can not easily be solved (you should catch every DB error, try a $this->db->reconnect(), terminate if this generates an error too).

This would puzzle me though, child scripts should not be allowed to touch resources owned by the parent script, that's a separate process... How exactly do you 'fork'?




Theme © iAndrew 2016 - Forum software by © MyBB