mysql server has gone away or connection timeout

If you do a lots of things in one php script this usually takes some time and mysql can gone away 😉 for this when you run new query you can run it with this function which will connect again to mysql if previous connection is closed from timeout


function run_query($sql){
global $link, $db;

if(!mysql_ping($link)){
$link = mysql_connect($db[‘host’], $db[‘user’], $db[‘pass’], true);
mysql_select_db($db[‘db’], $link);
}

return mysql_query($sql, $link);

}

С етикет: , ,
Публикувано в linux, php

Вашият коментар

Вашият имейл адрес няма да бъде публикуван. Задължителните полета са отбелязани с *

*