php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40850 The connection to a MySQL Server don't return FALSE if the connection failed.
Submitted: 2007-03-18 22:35 UTC Modified: 2007-03-19 09:28 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: serge dot dominici at e-sd dot org Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.2.1 OS: win32
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: serge dot dominici at e-sd dot org
New email:
PHP Version: OS:

 

 [2007-03-18 22:35 UTC] serge dot dominici at e-sd dot org
Description:
------------
When creating the mysqli object, it don't return FALSE as said in the documentation, if the connection failed.

Reproduce code:
---------------
try {
 $this->mysqli = @new mysqli('localhost', 'bad_user', 'password', 'db');
 if ($this->mysqli == FALSE) {
  throw new Exception("Connection failed !");
 }
 var_dump($this->mysqli);
 var_export($this->mysqli);
} catch (Exception $e) {
 $e->showStackTrace();
}

Expected result:
----------------
object(mysqli)#5 (0) { } mysqli::__set_state(array( ))


Actual result:
--------------
Connection failed !

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-18 22:37 UTC] serge dot dominici at e-sd dot org
Sorry i have invert 'Expected result' and 'Actual result'
 [2007-03-19 09:28 UTC] tony2001@php.net
Operator "new" cannot return FALSE by design, it creates new object.
Use mysqli_connect() function (which is actually an alias for MySQLi::__construct()) and it works just fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC