|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-04 09:39 UTC] scouture at novo dot ca
Description:
------------
When openning 2 connections to a MySQL server using mysql_connect or mysql_pconnect, if the first connection is valid and the second not (in my code, the password for the second connection is wrong), then mysql_error() return an empty string and mysql_errno return 0 witch is the errno saying that there has been no problem.
Reproduce code:
---------------
echo "first connection<br><br>";
$conn1 = mysql_connect($validIp&Port,$validUser,$validPassword);
if($conn1 == false)
{
echo "<hr>mysql_error : ".mysql_error()."<br>";
echo "mysql_errno : ".mysql_errno()."<hr>";
}
else
echo "ok connected 1";
echo "<hr>second connection<br><br>";
$conn2 = mysql_connect ($validIp&Port,$validUser,$NOTvalidPassword);
if($conn2 == false)
{
echo "<hr>mysql_error : ".mysql_error()."<br>";
echo "mysql_errno : ".mysql_errno()."<hr>";
}
else
echo "ok connected 2";
Expected result:
----------------
mysql_error should be
Access denied for user: 'novolog@ChewbaGoulh' (Using password: YES)
mysql_errno should be
1045
Actual result:
--------------
/**display**/
first connection
ok connected 1
--------------------------------------------------------------------------------
second connection
Warning: mysql_connect(): Access denied for user: 'novolog@ChewbaGoulh' (Using password: YES) in D:\Program Files\Apache Group\Apache2\htdocs\Intranet Novolog\tesMysql.php on line 20
--------------------------------------------------------------------------------
mysql_error :
mysql_errno : 0
--------------------------------------------------------------------------------
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 20:00:02 2025 UTC |
I've got the same result EVEN with the new_link parameter set to TRUE. echo "first connection<br><br>"; $conn1 = mysql_connect($validIp&Port,$validUser,$validPassword, true); if($conn1 == false) { echo "<hr>mysql_error : ".mysql_error()."<br>"; echo "mysql_errno : ".mysql_errno()."<hr>"; } else echo "ok connected 1"; echo "<hr>second connection<br><br>"; $conn2 = mysql_connect ($validIp&Port,$validUser,$NOTvalidPassword, true); if($conn2 == false) { echo "<hr>mysql_error : ".mysql_error()."<br>"; echo "mysql_errno : ".mysql_errno()."<hr>"; } else echo "ok connected 2";Ok, I have redone my home work and recheck the docs for those two functions. But, there is still something I don't understand in there behavior. If I try to open a link for the first time with $test = mysql_connect ($ip, $user, $password, TRUE) if($test == false) { echo mysql_errno(); } if I enter a wrong user, I'll get the 1045 error, right ? from docs Note: If the optional argument is specified the given link is used to retrieve the error code. If not, the last opened link is used. In this case, I do not specify any link to mysql_errno so it should use the last opened link, wich in this case, because it's the first time a link is trying to be opened, do not exist. But, I can retrieve the right errno anyway. If I open a valid link, then try to reopened a second one using $test2 = mysql_connect ($ip, $user, $password, TRUE) if($test2 == false) { echo mysql_errno(); } Has I understand, because there is already a valid link, mysql_errno() use that link (because none is specified). But, I have pass the parametre new_link set to TRUE, so those 2 functions should behave like there is no valid connection opened before, like in the first time when I try to open a link and there is none already opened and return me 1045. If the new_link == FALSE, then they should use the last link opened but in the case that new_link == TRUE, they should behave like there is no other link opened. I understand that this may not be a bug to you, but I'm sure you can say that the behavior of the functions mysql_error() and mysql_errno() (PHP 3, PHP 4) have not followed the modification regarding mysql_connect() and the new_link parameter (PHP 4.2.0).