|  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
Private report: No CVE-ID: None
 [2004-09-10 16:13 UTC] Nico dot Laus dot 2001 at gmx dot de
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());

Expected result:
Connect failed: <error> 

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-11 14:23 UTC]
Please try using this CVS snapshot:
For Windows:

this script works fine for me: 
   $mysqli = @new mysqli("localhost", "nonexistentuser", 
"foo", "test"); 
   if (mysqli_connect_errno()) { 
      printf("Connect failed: %s\n", 
   $mysqli->connect("localhost", "root", "", "test"); 
   if (!mysqli_connect_errno()) { 
      printf("%s\n", $mysqli->server_info); 
Connect failed: Access denied for user 
'nonexistentuser'@'localhost' (using password: YES) 
 [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 
-> 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-2023 The PHP Group
All rights reserved.
Last updated: Fri Mar 31 10:04:43 2023 UTC