note 27906 rejected from function.mysql-connect by jmcastagnetto

From: Date: Tue, 24 Dec 2002 08:34:34 +0000
Subject: note 27906 rejected from function.mysql-connect by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-41252@lists.php.net to get a copy of this message
If you try to open a second connection with mysql_connect() when you already have one open, you don't get the proper error messages put in mysql_error() and mysql_errno(). Tested with version 4.1.2. Example: <?php // valid connection data $host1 = "localhost"; $user1 = "bob"; $pass1 = "password"; // invalid connection data $host2 = "localhoooost"; $user2 = "harry"; $pass2 = "password"; echo "** Connect with valid data, all is fine:"; if(!($link1 = @mysql_connect($user1, $pass1, $host1))) { echo mysql_error(); } echo "** No errors received. Connecting with invalid data first time"; if(!($link2 = @mysql_connect($host2, $user2, $pass2))) { echo mysql_error(); } echo "** No error messages received yet, closing first link."; mysql_close($link1); echo "** First link closed, attempting to reconnect with invalid data:"; if(!($link2 = @mysql_connect($host2, $user2, $pass2))) { echo mysql_error(); } echo "** Error messages appear, like they should have the first time."; ?> Output from this program: ** Connect with valid data, all is fine: ** No errors received. Connecting with invalid data first time: ** No error messages received yet, closing first link. ** First link closed, attempting to reconnect with invalid data: Unknown MySQL Server Host 'localhoooost' (2) ** Error messages appear, like they should have the first time.

« previous php.notes (#41252) next »