#40850 [Opn->Bgs]: The connection to a MySQL Server don't return FALSE if the connection failed.

From: Date: Mon, 19 Mar 2007 09:28:59 +0000
Subject: #40850 [Opn->Bgs]: The connection to a MySQL Server don't return FALSE if the connection failed.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110492@lists.php.net to get a copy of this message
ID: 40850 Updated by: tony2001@php.net Reported By: serge dot dominici at e-sd dot org -Status: Open +Status: Bogus Bug Type: MySQLi related Operating System: win32 PHP Version: 5.2.1 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2007-03-18 22:37:38] serge dot dominici at e-sd dot org Sorry i have invert 'Expected result' and 'Actual result' ------------------------------------------------------------------------ [2007-03-18 22:35:53] 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 ! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40850&edit=1

« previous php.bugs (#110492) next »