Index: include/func/func.db.php diff -u include/func/func.db.php:1.9.2.17 include/func/func.db.php:1.9.2.18 --- include/func/func.db.php:1.9.2.17 Fri Apr 11 22:11:17 2008 +++ include/func/func.db.php Mon May 12 17:42:20 2008 @@ -79,6 +79,12 @@ __add_mark(); $result = mysql_query($query); + + if (!$result && preg_match("/Lost connection|server has gone away/", mysql_error())) { + db_connection(); + $result = mysql_query($query); + } + $t_end = func_microtime(); if (defined("START_TIME")) { $__sql_time += func_microtime()-$t; @@ -620,4 +626,23 @@ func_header_location("error_message.php?access_denied&id=79"); } +# +# The function uses the global $sql_info array: +# $sql_info = array($sql_host, $sql_user, $sql_password, $sql_db); +# + +function db_connection () { + global $sql_info; + + if (empty($sql_info)) return false; + + $db_connect_limit = 5; + $sql_connection = false; + while ($db_connect_limit-- > 0 && !$sql_connection) { + $sql_connection = @db_connect($sql_info[0], $sql_info[1], $sql_info[2]); + } + db_select_db($sql_info[3]) || die("Sorry, the shop is inaccessible temporarily. Please try again later."); + return $sql_connection; +} + ?> Index: init.php diff -u init.php:1.31.2.41 init.php:1.31.2.42 --- init.php:1.31.2.41 Thu May 8 13:38:03 2008 +++ init.php Mon May 12 17:42:20 2008 @@ -343,9 +343,11 @@ # # Connect to database # -$db_connect_limit = 5; -while ($db_connect_limit-- > 0 && !@db_connect($sql_host, $sql_user, $sql_password)) { } -db_select_db($sql_db) || die("Sorry, the shop is inaccessible temporarily. Please try again later."); + +global $sql_info; +$sql_info = array($sql_host, $sql_user, $sql_password, $sql_db); + +db_connection(); $tmp = func_query_first("SHOW VARIABLES LIKE 'max_allowed_packet'"); $sql_max_allowed_packet = intval($tmp['Value']);