note 84159 deleted from function.mysql-ping by tularis

From: Date: Tue, 01 Jul 2008 15:06:08 +0000
Subject: note 84159 deleted from function.mysql-ping by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141042@lists.php.net to get a copy of this message
Note Submitter: max at phoenixweb dot it Reason: bad code ---- Thanks to Dustin Hawkins i made this function, maybe can be usefull for your scripts: <?php function connect_mysql() { global $CONN, $MYSQL; if (!$CONN) { $CONN = @mysql_connect ($MYSQL["HOST"], $MYSQL["USER"], $MYSQL["PASS"]) or die ("error on connecting: " . mysql_error()); @mysql_select_db ($MYSQL["NAME"], $CONN) or die ("error on selecting database: " . mysql_error()); } else { if (!@mysql_ping($CONN)) { mysql_close($CONN); $CONN = @mysql_connect ($MYSQL["HOST"], $MYSQL["USER"], $MYSQL["PASS"]) or die ("error on re-connecting: " . mysql_error()); @mysql_select_db ($MYSQL["NAME"], $CONN) or die ("error on selecting database: " . mysql_error()); } } } //call this function before every mysq_query(); and everything goes right. ?> $MYSQL is an array with all configs needed in order to connect

« previous php.notes (#141042) next »