Simple MySQL query that auto connects to a server if connection has timed out, or isn't there to begin with. Use in place of mysql_query.
Example:
$result = my_mysql_query("SELECT * FROM foo
.bar
");
In the code, we see SQL_SERVER, SQL_USER, SQL_PASS, and SQL_DB. These are defined using the define(); function.
Example:
define('SQL_SERVER','localhost');
function my_mysql_query($query, $link_identifier = false)
{
if (!mysql_ping()) {
mysql_close();
mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS);
mysql_select_db(SQL_DB);
}
if ($link_identifier === false)
return mysql_query($query);
else
return mysql_query($query, $link_identifier);
}