php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30051 connecting to MySQL with wrong data cannot be checked with mysqli_connect()
Submitted: 2004-09-10 16:13 UTC Modified: 2004-09-13 15:24 UTC
From: Nico dot Laus dot 2001 at gmx dot de Assigned:
Status: Closed Package: MySQLi related
PHP Version: 5.0.1 OS: Linux 2.6.8.1
Private report: No CVE-ID: None
 [2004-09-10 16:13 UTC] Nico dot Laus dot 2001 at gmx dot de
Description:
------------
given the example below from the mysqli documentation, I 
tried to connect to my MySQL server with wrong data to 
see, what happens, if the connection really fails. 
 
unfortunately the constructor does trigger a WARNING 
itself and does not return FALSE, as documented. The 
mysqli_connect_errno() does only return 0 and even the 
$mysqli->errno variable does not have any value. So I 
cannot find out, if the connect really has failed or not. 
 
I'm using MySQL 4.1.4 

Reproduce code:
---------------
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
 
 /* check connection */ 
 if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
 }

Expected result:
----------------
Connect failed: <error> 

Actual result:
--------------
 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-11 14:23 UTC] georg@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

this script works fine for me: 
 
<?php 
   $mysqli = @new mysqli("localhost", "nonexistentuser", 
"foo", "test"); 
  
   if (mysqli_connect_errno()) { 
      printf("Connect failed: %s\n", 
mysqli_connect_error()); 
   } 
  
   $mysqli->connect("localhost", "root", "", "test"); 
   if (!mysqli_connect_errno()) { 
      printf("%s\n", $mysqli->server_info); 
      $mysqli->close(); 
   } 
?> 
 
Output: 
Connect failed: Access denied for user 
'nonexistentuser'@'localhost' (using password: YES) 
5.0.2-alpha-debug-log 
 
 
 
 [2004-09-13 15:24 UTC] Nico dot Laus dot 2001 at gmx dot de
ok, I checked with cvs and your example worked, but not my 
script 
-> then I discovered, that there could have been another 
successfull connect and this may be the reason for not 
reporting the failed connection (although I do not really 
understand how this can happen, because the connection 
check does take place directly after connecting) 
I rewrote my script and now it works - so I consider this 
"bug" as closed 
-> thanks for your help
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Aug 22 09:01:27 2019 UTC