bilis_money Posted July 11, 2006 Share Posted July 11, 2006 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 forthis please don't hesitate to share it to me, because i want to know it.Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/ Share on other sites More sharing options...
ShogunWarrior Posted July 11, 2006 Share Posted July 11, 2006 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 mysqlmysql_close($conn);renderHtml($x....);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/#findComment-56134 Share on other sites More sharing options...
zq29 Posted July 11, 2006 Share Posted July 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/#findComment-56139 Share on other sites More sharing options...
hvle Posted July 11, 2006 Share Posted July 11, 2006 I don't close my connection. The script close automaticly upon exit anyway.And I used pconnect (persistent connection) instead of connect.Personally, I don't see any security issue with that. Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/#findComment-56141 Share on other sites More sharing options...
bilis_money Posted July 11, 2006 Author Share Posted July 11, 2006 nice!, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/#findComment-56151 Share on other sites More sharing options...
wildteen88 Posted July 11, 2006 Share Posted July 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14286-when-is-the-right-time-to-close-a-mysql-database/#findComment-56306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.