|
Posted by Andy Hassall on 09/14/05 21:55
On 14 Sep 2005 06:14:12 -0700, "Nils Bandener" <nils.netz@applion.net> wrote:
>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.
If you don't call mysql_close(), you're already using only one MySQL
connection throughout the life of the request anyway, no matter how many times
you call mysql_connect.
http://uk.php.net/mysql_connect
" If a second call is made to mysql_connect() with the same arguments, no new
link will be established, but instead, the link identifier of the already
opened link will be returned."
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Navigation:
[Reply to this message]
|