|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-05-14 03:47 UTC] zeusgerde at arcor dot de
Description: ------------ E_WARNING when accessing properties or methods of MySQLi object if connection fails I know other people already reported this kind of issue: http://bugs.php.net/bug.php?id=33635 http://bugs.php.net/bug.php?id=34828 http://bugs.php.net/bug.php?id=36949 http://bugs.php.net/bug.php?id=45935 http://bugs.php.net/bug.php?id=45940 http://bugs.php.net/bug.php?id=50772 though I think telling the user "couldn't fetch *mysqli*" is just wrong because PHP is able to use the MySQLi object and even some of its properties or methods (e.g. MySQLi::$client_version or MySQLi::$connect_errno) i am not sure if this is a real bug report or may be a feature request. but I think it would help other people if the warning says something like "mysqli is not connected" or may be E_WARNING should not be raised at all. -- PHP 5.3.2 (cli) (built: May 14 2010 03:25:13) MySQLi Client API library version 5.1.45 Test script: --------------- <?php error_reporting(E_ALL); // not bug related ini_set('display_errors', 1); // not bug related $foo = new MySQLi('localhost', 'root', 'wrongpassword'); // alternative to the line above, same result: $foo = new MySQLi(); var_dump($foo); ?> Expected result: ---------------- object(mysqli)#1 (17) { /* ... */ } Actual result: -------------- Lots of "Warning: var_dump(): Couldn't fetch mysqli in [...]" (for nearly every single key in mysqli) object(mysqli)#1 (17) { /* content as expected */ } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 20:00:01 2025 UTC |
The intent of the connect_errno method is to determine if an connection error occurred...one would think. The programmer is expecting the chance a connection error occurred. Don't error-out if he asks. $host = 'bad_host';// FORCE AN ERROR -- debug $mysqli = @new mysqli($host, NTSM_USER, PWD_NTSM, NTSM_INSTANCE); if ($mysqli->connect_errno) { do something } One would expect the code above to not annoy the user with an echoed warning. I have to use @$mysqli->connect_errno, but I have no return from the method call. Instead I receive 'Couldn't fetch mysqli in', why is a fetch even attempted with this method? Look at the local object and see if it contains an error status and return it.