note 72395 added to function.mysql-close

From: Date: Wed, 17 Jan 2007 14:25:28 +0000
Subject: note 72395 added to function.mysql-close
Groups: php.notes 
Request: Send a blank email to php-notes+get-121834@lists.php.net to get a copy of this message
RonS is mostly incorrect about mysql_close. It's not necessarily good programming practice to always explicitly close your database connect as it might be in other languages. Your connection will be closed as soon as your script is finished, so there is almost never a need to call mysql_close at the end of a script. If you have a script that does a lot of queries, it's dangerous to overuse the mysql_close function, as constantly opening and closing a connection can cause a lot of overhead, especially if you're connecting to a remote database. If you are already connected to a database and try to use mysql_connect again on the same database, then the same connection will be returned, and no new connection will be opened. So, it's safe to overuse mysql_connect without overusing mysql_close. If you need to open multiple connections to the same database, then create two connections with mysql_connect with the extra boolean argument to force a new connection to be made without reusing the old connection. The only compelling reason for using mysql_close is if your script is assuredly finished with the connection, but still has a lot of processing left to do. It is almost never beneficial to open and close the same connection throughout a script. ---- Server IP: 69.147.83.197 Probable Submitter: 71.159.54.54 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-close.php Edit -- https://master.php.net/note/edit/72395 Del: integrated -- https://master.php.net/note/delete/72395/integrated Del: useless -- https://master.php.net/note/delete/72395/useless Del: bad code -- https://master.php.net/note/delete/72395/bad+code Del: spam -- https://master.php.net/note/delete/72395/spam Del: non-english -- https://master.php.net/note/delete/72395/non-english Del: in docs -- https://master.php.net/note/delete/72395/in+docs Del: other reasons-- https://master.php.net/note/delete/72395 Reject -- https://master.php.net/note/reject/72395 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#121834) next »