note 83707 rejected from function.mysql-connect by yannick

From: Date: Sun, 08 Jun 2008 16:44:45 +0000
Subject: note 83707 rejected from function.mysql-connect by yannick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140245@lists.php.net to get a copy of this message
Note Submitter: coderlit at G dot mail\ dot com ---- The note from angelo [at] mandato <dot> com is a good way to reuse the msyql connection, like mysql connection pooling. However, you need to remove the $g_link = false; in the file. Other wise, everytime you include this file, the mysql connection is set to false, and you have to call the mysql_connect again to connect to the sql server, even though you may have already have live mysql connection ready for use. <?php //need to remove this line to resue the connection resource $g_link = false; function GetMyConnection() { global $g_link; if( $g_link ) return $g_link; $g_link = mysql_connect( 'localhost', 'dbuser', 'dbpass') or die('Could not connect to mysql server.' ); mysql_select_db('wordpress', $g_link) or die('Could not select database.'); return $g_link; } function CleanUpDB() { global $g_link; if( $g_link != false ) mysql_close($g_link); $g_link = false; } ?>

« previous php.notes (#140245) next »