CodeIgniter Forums
CI_DB_driver Bug? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: CI_DB_driver Bug? (/showthread.php?tid=81)



CI_DB_driver Bug? - Gavin - 11-03-2014

In the course of using codeigniter, occasionally following error, do not know bug?

Code:
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): MySQL server has gone away
Filename: mysqli/mysqli_driver.php
Line Number: 111
Backtrace:
File: D:\wwwroot\travl\application\core\MY_Controller.php
Line: 13
Function: __construct
File: D:\wwwroot\travl\application\core\MY_Controller.php
Line: 56
Function: __construct
File: D:\wwwroot\travl\application\controllers\Hotel.php
Line: 9
Function: __construct
File: D:\wwwroot\travl\index.php
Line: 282
Function: require_once



RE: CI_DB_driver Bug? - kenji - 11-03-2014

I don't think is a CI bug

http://dev.mysql.com/doc/refman/5.5/en/gone-away.html


RE: CI_DB_driver Bug? - Rufnex - 11-03-2014

This should be a problem of you server settings or installations and could be erverything.
Try to use mysql instead of mysqli.


RE: CI_DB_driver Bug? - kilishan - 11-03-2014

I've seen this happen on a project that I worked on before. I think the server settings had a 5 minute timeout and we were doing some long running processes that ended up losing connection.

You can use
Code:
$this->db->reconnect();
to restore your connection. We just did it periodically in our MY_Model. There was a bit of an overhead but things kept running that way.


RE: CI_DB_driver Bug? - InsiteFX - 11-03-2014

This can be caused by several different things.

You can try the following:

MySQL my.cnf or windows my.ini
max_allowed_packet = 32M

wait_timeout = <huge number>
connect_timeout = <also a huge number>

php.ini
mysql.connect_timeout = -1


RE: CI_DB_driver Bug? - Gavin - 11-04-2014

Thanks for everybody!

Add $this->db->reconnect(); in MY_Model has been resolved


RE: CI_DB_driver Bug? - Narf - 11-04-2014

(11-03-2014, 09:29 AM)Rufnex Wrote: This should be a problem of you server settings or installations and could be erverything.
Try to use mysql instead of mysqli.

That driver is deprecated both by CI and by PHP itself, please don't recommend it.


RE: CI_DB_driver Bug? - Rufnex - 11-04-2014

@Narf: you're right .. i forgott to write just for checking the connection stuff for indicate it it is a persisten connection problem.


RE: CI_DB_driver Bug? - summer - 02-10-2015

Hi everyone!

I'm also facing the same issue, i'm getting this error occasionally:
Code:
A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect() [mysqli.real-connect]: MySQL server has gone away

Filename: mysqli/mysqli_driver.php

Line Number: 135

Backtrace:

File: E:\wamp\www\ace_admin\application\controllers\Manager.php
Line: 10
Function: __construct

File: E:\wamp\www\ace_admin\index.php
Line: 292
Function: require_once

i'm auto loading my database like this:
Code:
$autoload['libraries'] = array('database', 'session');

and below are my database config settings:
Code:
$active_group = 'development';
$query_builder = TRUE;

$db['development'] = array(
    'dsn'    => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'admin',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'autoinit' => TRUE,
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

I need a solution where i don't have to change my server's php settings, if not possible then need to suppress only this warning as it doesn't have any effect on my code, i'm reconnecting db on my models in their constructors.

Thanks.


RE: CI_DB_driver Bug? - InsiteFX - 02-10-2015

Did you try using:

PHP Code:
$this->db->reconnect();