ID: 50772
Updated by: [email protected]
Reported By: elmo dot allen at iki dot fi
-Status: Open
+Status: Assigned
Bug Type: MySQLi related
-Operating System: Windows 7
+Operating System: *
-PHP Version: 5.3.1
+PHP Version: 5.*, 6
-Assigned To:
+Assigned To: mysql
Previous Comments:
------------------------------------------------------------------------
[2010-01-15 19:34:47] elmo dot allen at iki dot fi
Description:
------------
Documentation states that calling mysqli::__construct() without
parameters (i.e. new mysqli()) should do the same as calling
mysqli_init(). It does not, however, return a working mysqli object, but
all the following calls to its methods only return Warning "Couldn't
fetch mysqli".
Using mysqli_init() directly works as intended, but using it makes
making derived mysqli classes much harder, if trying to use
real_connect(), because derived classes can only call their parent's
constructor, not mysqli_init().
The following code is by design trying a connection and failing (with
MySQL server not running) and gracefully admitting it with an error
message (warnings not tried to be silenced here).
Not working in PHP 5.2.8 either. No newer snapshots for Windows seem to
be available.
Reproduce code:
---------------
<?php
// Does not return a working object
$db1 = new mysqli();
// These calls fail
$db1->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3);
$db1->real_connect("localhost");
if(mysqli_connect_error()) echo "error 1";
else echo "ok 1";
// This works
$db2 = mysqli_init();
// And these calls work as intended (give correct error msgs when
connection fails)
$db2->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3);
$db2->real_connect("localhost");
if(mysqli_connect_error()) echo "error 2";
else echo "ok 2";
?>
Expected result:
----------------
Warning: mysqli::real_connect() [mysqli.real-connect]: [2002] A
connection attempt failed because the connected party did not (trying
to connect via tcp://localhost:3306) in C:\Users\Elmo\Documents\Web
server\test.php on line 7
Warning: mysqli::real_connect() [mysqli.real-connect]: (HY000/2002): A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.
in C:\Users\Elmo\Documents\Web server\test.php on line 7
error 1
Warning: mysqli::real_connect() [mysqli.real-connect]: [2002] A
connection attempt failed because the connected party did not (trying
to connect via tcp://localhost:3306) in C:\Users\Elmo\Documents\Web
server\test.php on line 13
Warning: mysqli::real_connect() [mysqli.real-connect]: (HY000/2002): A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.
in C:\Users\Elmo\Documents\Web server\test.php on line 13
error 2
Actual result:
--------------
Warning: mysqli::options() [mysqli.options]: Couldn't fetch mysqli in
C:\Users\Elmo\Documents\Web server\test.php on line 6
Warning: mysqli::real_connect() [mysqli.real-connect]: Couldn't fetch
mysqli in C:\Users\Elmo\Documents\Web server\test.php on line 7
ok 1
Warning: mysqli::real_connect() [mysqli.real-connect]: [2002] A
connection attempt failed because the connected party did not (trying
to connect via tcp://localhost:3306) in C:\Users\Elmo\Documents\Web
server\test.php on line 13
Warning: mysqli::real_connect() [mysqli.real-connect]: (HY000/2002): A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond.
in C:\Users\Elmo\Documents\Web server\test.php on line 13
error 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50772&edit=1