• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI_DB_driver Bug?

#1
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
Reply

#2
I don't think is a CI bug

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

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

Reply

#4
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.
Reply

#5
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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#6
Thanks for everybody!

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

#7
(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.
Reply

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

Reply

#9
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.
Reply

#10
Did you try using:

PHP Code:
$this->db->reconnect(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.