From: elmo dot allen at iki dot fi
Operating system: Windows 7
PHP version: 5.3.1
PHP Bug Type: MySQLi related
Bug description: mysqli constructor without parameters does not return a
working mysqli object
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 bug report at http://bugs.php.net/?id=50772&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50772&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50772&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50772&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50772&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=50772&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50772&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=50772&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=50772&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=50772&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=50772&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=50772&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=50772&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=50772&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50772&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50772&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50772&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=50772&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=50772&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=50772&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=50772&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=50772&r=mysqlcfg