Hello,
I updated an eGroupware installation from 1.4 (using MySQLi) to 1.6 and
ran across the same issue as described in [1] ("Couldn’t fetch mysqli"
errors). I wrote two patches to correct this and I will describe them
in the following. (I can submit them in another format in case you
don’t use such patches.)
I found out that when the egw_db instance from the session is
unserialized, it doesn’t reconnect. I found out that this was because
the following check in class.egw_db.inc.php, around line 473, method
connect(), didn’t work:
// next ADOdb version: if (!$this->Link_ID->isConnected()) $this->Link_ID->Connect();
if (!$this->Link_ID->_connectionID) $this->Link_ID->Connect();
The _connectionID variable contained a true value, namely a MySQLi
object, which couldn’t process any queries though. There seems to be
no way to cleanly determine whether a possibly unserialized MySQLi
connection holds a valid coonnection or not.
Therefore I added a __sleep() method and a _connection_sleeping
attribute to the egw_db class. _connection_sleeping is set to true by
__sleep() and a reconnect is done by connect() if _connection_sleeping
is true. (I didn’t force a reconnect when __wakeup() is called, as I
thought it might be called multiple times, which doesn’t seem to be the
case though. This might be a simpler solution which you might prefer.)
I tried to add the check to the above-mentioned check but then no
database would be selected after Link_ID->Connect() was called.
Therefore I added the check further up (see the patch). I guess that
the above-mentioned check should be removed, as it’s broken and doesn’t
do any error reporting.
However, the patch introduced a new bug: After unserialization, the
database backend would be switched from MySQLi to MySQL as the $Type
attribute had changed. The second patch fixes that.
Regards,
Milan
–
http://mjh.name/