note 83706 added to function.mysql-connect
| From: | coderlit at G dot mail dot com | Date: | Sun, 08 Jun 2008 15:56:57 +0000 |
| Subject: | note 83706 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140243@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.156.94.240
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/83706
Del: integrated -- https://master.php.net/note/delete/83706/integrated
Del: useless -- https://master.php.net/note/delete/83706/useless
Del: bad code -- https://master.php.net/note/delete/83706/bad+code
Del: spam -- https://master.php.net/note/delete/83706/spam
Del: non-english -- https://master.php.net/note/delete/83706/non-english
Del: in docs -- https://master.php.net/note/delete/83706/in+docs
Del: other reasons-- https://master.php.net/note/delete/83706
Reject -- https://master.php.net/note/reject/83706
Search -- https://master.php.net/manage/user-notes.php