note 27906 added to function.mysql-connect
| From: | melon at online dot no | Date: | Tue, 24 Dec 2002 07:59:12 +0000 |
| Subject: | note 27906 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41248@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.
--
http://www.php.net/manual/en/function.mysql-connect.php
http://master.php.net/manage/user-notes.php?action=edit+27906
http://master.php.net/manage/user-notes.php?action=delete+27906
http://master.php.net/manage/user-notes.php?action=reject+27906