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

Π’Π°ΡˆΠΈΡΡ‚ ΠΊΠΎΠΌΠ΅Π½Ρ‚Π°Ρ€

Π’Π°ΡˆΠΈΡΡ‚ ΠΈΠΌΠ΅ΠΉΠ» адрСс няма Π΄Π° бъдС ΠΏΡƒΠ±Π»ΠΈΠΊΡƒΠ²Π°Π½. Π—Π°Π΄ΡŠΠ»ΠΆΠΈΡ‚Π΅Π»Π½ΠΈΡ‚Π΅ ΠΏΠΎΠ»Π΅Ρ‚Π° са отбСлязани с *

*