php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73462 Persistent connections don't set $connect_errno
Submitted: 2016-11-04 20:53 UTC Modified: -
From: php at darkain dot com Assigned:
Status: Closed Package: MySQLi related
PHP Version: 7.0.12 OS: Debian 8
Private report: No CVE-ID: None
 [2016-11-04 20:53 UTC] php at darkain dot com
Description:
------------
Tested on:
PHP 5.6.27-1~dotdeb+7.1 (cli) (built: Oct 15 2016 01:36:00)
PHP 7.0.12-1~dotdeb+8.1 (cli) ( NTS )

mysqli_connect_errno() and $mysql->connect_errno are not set at all after a successful persistent connection is re-connected.

In the example provided, the 3rd call to "new mysqli" is re-using the connection from the first call, however after the 3rd "new mysqli", mysqli_connect_errno() still returns the error code from the 2nd call, rather than returning 0 for a successful reconnection. This makes it virtually impossible to tell if the 3rd connection succeeded or not for proper application level error handling.

Note: This also effects mysqli_connect_error() and $mysqli->connect_error

Test script:
---------------
$server	= 'p:192.168.1.99';
$user	= 'USERNAME';
$pass	= 'PASSWORD';
$db	= 'DATABASE';

$mysql_1 = @new mysqli($server, $user, $pass, $db);
var_dump(mysqli_connect_errno());
@$mysql_1->close();

$mysql_2 = @new mysqli('DOESNT-EXIST', $user, $pass, $db);
var_dump(mysqli_connect_errno());
@$mysql_2->close();

$mysql_3 = @new mysqli($server, $user, $pass, $db);
var_dump(mysqli_connect_errno());
@$mysql_3->close();

Expected result:
----------------
int(0)
int(2005)
int(0)


Actual result:
--------------
int(0)
int(2005)
int(2005)


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-03 11:19 UTC] nikic@php.net
Automatic comment on behalf of github@darkain.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=cfd6e1484283f9d693e457320e6a0d82422b9b33
Log: Fix Bug #73462 - Persistent connections don't set $connect_errno
 [2017-01-03 11:19 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 02:01:28 2024 UTC