ID: 14279 Updated by: zak Reported By: [EMAIL PROTECTED] Old Status: Assigned Status: Closed Bug Type: Feature/Change Request Operating System: Linux-i386 PHP Version: 4.0.6 Assigned To: zak New Comment:
I chatted about this idea with Yasuo Ohgaki - he pointed out a few potential issues with the change. While having the MySQL extension automatically set a new default connection might be more convenient, it would likely introduce another set of confusing behaviors to the function. Currently the behavior of many of the MySQL functions is: Accept an optional connection argument. If no connection argument is given, the last connection opened is used by default. If no connection is open, the function attempts to connect to a MySQL database by calling mysql_connect() without arguments. We probably should not make this any more complex. The current behavior has been in place for a long time - long enough that we should not break backwards compatibility. I hope that my earlier suggestions on a solution serve you well for your problem. I am closing this request. Previous Comments: ------------------------------------------------------------------------ [2001-12-02 03:06:52] [EMAIL PROTECTED] Perhaps the code should be changed so that when the default connection is closed, the next available connection is set as the default. If no one disagrees, I will do this. However, given that the MySQL functions open a connection to localhost if no default connection is set, I am changing this from a bug to a feature/change request. Two additional notes on this: Monty Widenius from MySQL recommends explicitly passing the connection handle to mysql_query() -- this helps avoid issues like this. Either change your mysql db auth settings or set your default MySQL host in your php.ini file to an invalid host. This will prevent you from accidentally connecting to a database that you do not wish to connect to. ------------------------------------------------------------------------ [2001-11-29 09:01:59] [EMAIL PROTECTED] We have a PHP script that suddenly changes its connection to a MySQL DB to the MySQL DB the localhost has. It wasn't suppose to do so. It happened after we created a new connection and then closed this new connection to use the old connection. The problem is that PHP now tries to connect to localhost, instead of using the only connection available. If it succeeds, it will connect to a host that could have nothing to do with the application (imagine a MySQL master-slave environment and the application is suppose to connect to the Master and, instead, it connects to the localhost where there's a slave and start updating data. This will corrupt the slave machine, which is what happened to us) <? $conn = mysql_connect("somehost", "user", "passwd"); echo mysql_get_host_info(), "<br>"; $conn2 = mysql_connect("anotherhost", "anotheruser", "anotherpasswd"); mysql_close($conn2); echo mysql_get_host_info(), "<br>"; ?> Ain't it a good reason for a review in this part of the code? ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14279&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]