Welcome Guest, Not a member yet? Register   Sign In
Mysqli frequent connection failures

(This post was last modified: 04-16-2015, 05:12 PM by bitwizard.)

Codigniter 3.0.0

I have been having lots of problems with the mysqli driver. Every third connection or so, I'd get a database connection error.  Tracking it down revealed that mysqli_init() was returning a null object and no error.  I suspect a MySQL or PHP config issue, but  I was not able to find anything in the mysql forums, so I changed the driver to use the mysqli_connect function instead, which works like a charm.  This code fragment is from my modified version of system/database/drivers/mysqli/mysqli_driver.php.  Except for the obvious (can't use options when connecting), does anyone see a problem with this solution?  (or better yet, ideas on the root cause).  

Thank you
// Commenting out the mysqi_init and real_connect functions:
 $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;              
 $mysqli = mysqli_init();
 $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
 if ($this->stricton)
   $mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode="STRICT_ALL_TABLES"');
 return $mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)
   ? $mysqli : FALSE;  

//Using mysqli_connect instead
 return mysqli_connect($hostname, $this->username, $this->password, $this->database, $port, $socket);

Theme © iAndrew 2016 - Forum software by © MyBB