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

This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Thank you!
Fixed in 5.2, 5.3 and HEAD

Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=294543
Log: Merge mysql changes
293815 Add possibility to restrain the number of levels (andrey)
293816 decrement correctly! (andrey)
293976 Fix for bug#50772 (andrey)
294302 Tests related to #50727 (uw)
294313 Fix a bug in mysqlnd where a pointer was not incremented (andrey)
294317 Fix second bug in that code, + instead of += thus not increasing (andrey)
294337 No idea which recent change has cause this little API change, however it is not (uw)
294421 Pass tsrmls to all functions, which might need it in the future. (andrey)