Bug #69884 [NEW]: mysqli->connect_error seems to be shared across objects
| From: | phpbugs at olemartin dot org | Date: | Fri, 19 Jun 2015 14:19:45 +0000 |
| Subject: | Bug #69884 [NEW]: mysqli->connect_error seems to be shared across objects | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-193697@lists.php.net to get a copy of this message | ||
From: phpbugs at olemartin dot org
Operating system: Ubuntu
PHP version: 5.5.26
Package: MySQLi related
Bug Type: Bug
Bug description:mysqli->connect_error seems to be shared across objects
Description:
------------
It seems that the \mysqli->connect_error and \mysqli->connect_errno
values (when using mysqli in the object-oriented mode) shares state
between all connections. This is not documented (it should at least have
a warning in the documentation).
When running the example code (make sure you point the first and last
connection to a valid MySQL server) i found that all connections
reported no errors, although the second one failed. Sometimes (although
I'm having a hard time reliably reproducing this) i'm pretty sure i've
also seen all three connections report errors (although the third and
last connection succeeded). Maybe this value is not overwritten when a
successful connection is done, in all code paths?
Either way, i think this should be either documented or fixed - as one
would not expect this information to be shared between instances when
the syntax doesn't indicate that. If this is a static property, i would
expect the documentation said to use \mysqli::$connect_error, but that
doesn't even work.
Test script:
---------------
$connections = array(
'Valid connection' => new mysqli('127.0.0.1', 'root',
'', 'test',
3306),
'Invalid connection' => @new mysqli('127.0.0.1', 'root',
'', 'test',
3307),
'Valid connection 2' => new mysqli('127.0.0.1', 'root',
'', 'test',
3306),
);
foreach($connections as $desc => $conn) {
echo "$desc:\n".
"connect_error = ".$conn->connect_error."\n".
"connect_errno = ".$conn->connect_errno."\n".
"ping = ".@$conn->ping()."\n\n".
}
Expected result:
----------------
Valid connection:
connect_error =
connect_errno = 0
ping = 1
Invalid connection:
connect_error = Connection refused
connect_errno = 2002
ping =
Valid connection 2:
connect_error =
connect_errno = 0
ping = 1
Actual result:
--------------
Valid connection:
connect_error =
connect_errno = 0
ping = 1
Invalid connection:
connect_error =
connect_errno = 0
ping =
Valid connection 2:
connect_error =
connect_errno = 0
ping = 1
--
Edit bug report at https://bugs.php.net/bug.php?id=69884&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69884&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69884&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69884&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69884&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69884&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69884&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69884&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69884&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69884&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69884&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69884&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69884&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69884&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69884&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69884&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69884&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69884&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69884&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69884&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69884&r=mysqlcfg