Welcome Guest, Not a member yet? Register   Sign In
$db->reconnect() Feature May Not Work
#1

[eluser]smartinec[/eluser]
According to the PHP and MySQL docs, the MySQL auto-reconnect feature has been disabled by default since version 5.0.13:

http://dev.mysql.com/doc/refman/5.0/en/a...nnect.html
http://www.php.net/manual/en/function.mysql-ping.php

I think the following code would work as expected, but I'm guessing the intention was for $db->reconnect() to already do this:

Code:
$db->reconnect(); // Sets $db->conn_id to FALSE on failure
$db->initialize(); // Reconnects when $db->conn_id is FALSE
#2

[eluser]Jamie Rumbelow[/eluser]
Calling reconnect() with auto-reconnect disabled in MySQL will throw an error, and depending on your error status in your config file and PHP install will display and log the error.

The best way to do it is just close the connection and reconnect manually with:

Code:
$this->db->close();
$this->db->initialize();
#3

[eluser]smartinec[/eluser]
I'm referring to the CI_DB::reconnect() function implemented in CodeIgniter 1.7.2 - not a MySQL reconnect() function.
#4

[eluser]Jamie Rumbelow[/eluser]
...which calls mysql_ping() in the background. If auto-reconnect (pinging) is disabled MySQL throws an error, which traces back to PHP which throws an error in turn.
#5

[eluser]smartinec[/eluser]
According to the PHP docs it throws a E_WARNING which would allow script execution to continue.
#6

[eluser]smartinec[/eluser]
My main point is, why was the CI_DB::reconnect() function implemented if it's useless to most people?
#7

[eluser]Jamie Rumbelow[/eluser]
But would still flash up a warning message. By manually disconnecting and reconnecting you don't have that problem.
#8

[eluser]Jamie Rumbelow[/eluser]
[quote author="smartinec" date="1258064513"]My main point is, why was the CI_DB::reconnect() function implemented if it's useless to most people?[/quote]

Good question. Why do EllisLab still support PHP4 when the majority of users have upgraded long ago? The fact remains that people STILL use it and will make use out of it. Swings and roundabouts.

I'm not trying to be argumentative, by the way, I'm just saying it like is Smile
#9

[eluser]smartinec[/eluser]
I just think it's odd to implement a new function to support an old feature.
#10

[eluser]Jamie Rumbelow[/eluser]
CodeIgniter's recent development (1.6 onwards specifically) has been pretty much fuelled by ExpressionEngine 2's development. So at some point somebody either requested this directly or it needed to be implemented in ExpressionEngine.




Theme © iAndrew 2016 - Forum software by © MyBB