php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #45646 Failed Connect Does Not Return FALSE
Submitted: 2008-07-28 14:49 UTC Modified: 2008-08-20 02:19 UTC
From: djneoform at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.6 OS: Win2k3 Standard
Private report: No CVE-ID: None
 [2008-07-28 14:49 UTC] djneoform at gmail dot com
Description:
------------
When a mysqli connection fails, the returned value is an empty mysqli object and not a bool(FALSE), this means any tests on the connection will not work, eg: if ($conn) { ... }

When the documentation: http://ca.php.net/manual/en/mysqli.connect.php

States:

"Return Values

Returns a object which represents the connection to a MySQL Server or FALSE if the connection failed."


Reproduce code:
---------------
<?php

	$connection = new mysqli('localhost', 'badinfo', 'badinfo', 'badinfo');

	var_dump($connection);
?>


Expected result:
----------------
bool(FALSE)

Actual result:
--------------
object(mysqli)#1 (0) { } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-29 21:01 UTC] jani@php.net
The manual page isn't quite clear that this concerns only the procedural style connect, not the OO way.
 [2008-07-29 21:04 UTC] djneoform at gmail dot com
What then is the proper way to verify that a connection has been established while using the OO version?

It seems innapropriate to be using a class object, only to use mysqli_connect_errno() in order to verify that the connection was established.
 [2008-08-20 02:19 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I changed the return values, and fixed the connect example to use proper OO syntax and added a notice explaining how to find out if a connection failed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 11:01:32 2024 UTC