eazyGen Posted August 29, 2011 Share Posted August 29, 2011 Hi guys. I am generally familiar with databases (mostly DB2), but I am a newbie when it comes to PHP and MySQL. I notice that in order to use a MySQL databases, a connection must first be made to the database and, somewhere along the line, that connection needs to be closed. I am thinking that to open a connection at the start of a script and then to close it at the end will work. However, if I do this for each and every script that accesses a database table, then there will be numerous open and close statements running through my application. I am wondering therefore is there is a generally accepted strategy for handling a database that minimises the amount of connection statements; or if the above is essential given the static state nature of a web page. Any assistance much appreciated. S Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/ Share on other sites More sharing options...
gizmola Posted August 29, 2011 Share Posted August 29, 2011 MySQL has an extremely fast and lightweight connection process. Since PHP has "page scope" and a typical php script runs very quickly, there is really no reason to worry about closing mysql connections, as the connection resource will be garbage collected when the script completes. Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263079 Share on other sites More sharing options...
eazyGen Posted August 29, 2011 Author Share Posted August 29, 2011 MySQL has an extremely fast and lightweight connection process. Since PHP has "page scope" and a typical php script runs very quickly, there is really no reason to worry about closing mysql connections, as the connection resource will be garbage collected when the script completes. Many thanks. I am using Apache and mySQL on my server and localhost. Is there any way I can see the number of open database connections on either or both? S Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263100 Share on other sites More sharing options...
gizmola Posted August 29, 2011 Share Posted August 29, 2011 The commands: show processlist; or show full processlist; Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263103 Share on other sites More sharing options...
eazyGen Posted August 29, 2011 Author Share Posted August 29, 2011 The commands: show processlist; or show full processlist; Hi. My apologies. I did not make myself clear. I assume the above are for command line access. Is there a way I can see this via a URL, or perhaps from phpMyAdmin? Thanks S Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263106 Share on other sites More sharing options...
gizmola Posted August 29, 2011 Share Posted August 29, 2011 Those are queries that will return a result set. In a php script or phpMyAdmin you wouldn't include the semicolon. Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263111 Share on other sites More sharing options...
eazyGen Posted August 29, 2011 Author Share Posted August 29, 2011 Those are queries that will return a result set. In a php script or phpMyAdmin you wouldn't include the semicolon. Thank you. S Quote Link to comment https://forums.phpfreaks.com/topic/245938-mysql-database-connection-strategy/#findComment-1263114 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.