Jump to content

when is the right time to close a MySQL database?


bilis_money

Recommended Posts

Ok, i know how to open and close a MySQL database with PHP.

But i'm really confuse when is the right time to close it after opening?
PLease if you have a bright answer and detailed and smart explaination for
this please don't hesitate to share it to me, because i want to know it.

Thank you very much.

Generally, you will close it when you know it will no longer be need so, you might do on a page:

[code]
<?php
$conn = mysql_connect(.....);

$conn = mysql_query($sql....);
//Use the database again
$x = getArticles($conn);

//Now we'll output html, no need for mysql
mysql_close($conn);

renderHtml($x....);
?>[/code]
You'll only want to use mysql_close when using mysql_pconnect. As persistant connections will not close themselves, hens perisistant connections. However non-persistant connects wont need thier connection closed manually as they exit automatically once the script has been executed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.