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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 06:01:29 2024 UTC