php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26114 mysql_errno() & mysql_error() not behaving right on a second connection
Submitted: 2003-11-04 09:39 UTC Modified: 2003-11-05 09:10 UTC
From: scouture at novo dot ca Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.3 OS: windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: scouture at novo dot ca
New email:
PHP Version: OS:

 

 [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
--------------------------------------------------------------------------------

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-04 09:45 UTC] scouture at novo dot ca
NOTE that mysql_error() & mysql_errno() are returning result has expected if the first connection failed. So, if the first connection and the second failed, both mysql_error() & mysql_errno() are ok for the first and the second connection.

But, if there is already a valid connection to the dbserver, they are not behaving right for the second in case of failling.

Hope that is clear enought...

Regards
 [2003-11-04 09:58 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Always use the link parameter when doing multiple connects in same scripts. This is no bug.

 [2003-11-04 10:27 UTC] scouture at novo dot ca
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";
 [2003-11-04 11:20 UTC] scouture at novo dot ca
Have you been able to reproduce the behavior with the new_link parameter set to TRUE like I did ?
 [2003-11-05 00:37 UTC] sniper@php.net
Please read the manual pages for mysql_errno() and mysql_error() about what parameters they accept and you'll
find out what I meant..

 [2003-11-05 09:10 UTC] scouture at novo dot ca
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).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 03:01:35 2025 UTC