Jump to content

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 actually don't even need to close it most of the time as the link to the server will be closed as soon as the execution of the script ends. You only need to close it with mysql_close() if you have a specific reason to do so.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.