Skip to content

Commit cfd6e14

Browse files
darkainnikic
authored andcommitted
Fix Bug #73462 - Persistent connections don't set $connect_errno
Persistent connections skipped resetting $connect_error and $connect_errno values This adds the "clear error" line to persistent connections for consistency
1 parent ff4e330 commit cfd6e14

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
- DOM:
1818
. Fixed bug #67474 (getElementsByTagNameNS filter on default ns). (aboks)
1919

20+
- Mysqli:
21+
. Fixed bug #73462 (Persistent connections don't set $connect_errno).
22+
(darkain)
23+
2024
- Mysqlnd:
2125
. Fixed issue with decoding BIT columns when having more than one rows in the
2226
result set. 7.0+ problem. (Andrey)

ext/mysqli/mysqli_nonapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne
183183
mysqlnd_restart_psession(mysql->mysql);
184184
#endif
185185
MyG(num_active_persistent)++;
186+
187+
/* clear error */
188+
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql));
189+
186190
goto end;
187191
} else {
188192
mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);

ext/mysqli/tests/bug73462.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #73462 (Persistent connections don't set $connect_errno)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifemb.inc');
7+
require_once('skipifconnectfailure.inc');
8+
?>
9+
--FILE--
10+
<?php
11+
require_once("connect.inc");
12+
13+
/* Initial persistent connection */
14+
$mysql_1 = new mysqli('p:'.$host, $user, $passwd, $db);
15+
$result = $mysql_1->query("SHOW STATUS LIKE 'Connections'");
16+
$c1 = $result->fetch_row();
17+
$result->free();
18+
$mysql_1->close();
19+
20+
/* Failed connection to invalid host */
21+
$mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db);
22+
@$mysql_2->close();
23+
24+
/* Re-use persistent connection */
25+
$mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db);
26+
$error = mysqli_connect_errno();
27+
$result = $mysql_3->query("SHOW STATUS LIKE 'Connections'");
28+
$c3 = $result->fetch_row();
29+
$result->free();
30+
$mysql_3->close();
31+
32+
if (end($c1) !== end($c3))
33+
printf("[001] Expected '%d' got '%d'.\n", end($c1), end($c3));
34+
35+
if ($error !== 0)
36+
printf("[002] Expected '0' got '%d'.\n", $error);
37+
38+
print "done!";
39+
?>
40+
--EXPECTF--
41+
done!

0 commit comments

Comments
 (0)