Posted by Nils Bandener on 09/14/05 16:14
Sandman wrote:
> I recommend doing a persistent connection to MySQL outside this function. This
> way, you're making one new MySQL connection for every time the function is run.
> If this is the only function that ever use MySQL, it's no big deal, but if it
> isn't.
>
> Lookup mysql_pconnect
mysql_pconnect() could cause a couple of other problems, because it
keeps the connection open *after* the HTTP request has been finished.
See:
http://www.php.net/manual/en/features.persistent-connections.php
Better use the normal connect and cache the connection for re-use. For
example this way:
function makeDatabaseConnection()
{
static $link;
if (!isset($link))
{
$link = mysql_connect(...);
}
}
With subsequent mysql calls you don't even have to know the connection
because the mysql functions will automatically use the last established
connection.
Nils
[Back to original message]
|