From fcf0c3e0cf2689283b17a067fefc5cd3bc319348 Mon Sep 17 00:00:00 2001 From: Vince Date: Tue, 8 Nov 2016 14:23:04 -0800 Subject: [PATCH 1/3] 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 --- ext/mysqli/mysqli_nonapi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index f1e805ce41c80..c97947b24aa43 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -185,6 +185,10 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne mysqlnd_restart_psession(mysql->mysql); #endif MyG(num_active_persistent)++; + + /* clear error */ + php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC); + goto end; } else { mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT); From f588b1fbadaebc65735d584abc8853ff1d17e89a Mon Sep 17 00:00:00 2001 From: Vince Date: Wed, 9 Nov 2016 22:11:14 -0800 Subject: [PATCH 2/3] Adding unit test for Bug #73462 --- ext/mysqli/tests/bug73462.phpt | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ext/mysqli/tests/bug73462.phpt diff --git a/ext/mysqli/tests/bug73462.phpt b/ext/mysqli/tests/bug73462.phpt new file mode 100644 index 0000000000000..9dfec2a66fd10 --- /dev/null +++ b/ext/mysqli/tests/bug73462.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #73462 (Persistent connections don't set $connect_errno) +--SKIPIF-- + +--FILE-- +close(); + + $mysql_2 = @new mysqli('DOESNT-EXIST', $user, $passwd, $db); + @$mysql_2->close(); + + $mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db); + $error = mysqli_connect_errno(); + $mysql_3->close(); + + if ($error !== 0) printf("[001] Expecting '0' got '%d'.\n", $error); + + print "done!"; +?> +--EXPECTF-- +done! From 0fd597fbc2da5d934e6f0fa9ddd2b47dd9d120a4 Mon Sep 17 00:00:00 2001 From: Vince Date: Thu, 10 Nov 2016 15:51:21 -0800 Subject: [PATCH 3/3] More complete unit test for Bug #73462 The connection is now verified to be persistent when. If the connection isn't persistent, then the bug wouldn't present itself anyways. --- ext/mysqli/tests/bug73462.phpt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ext/mysqli/tests/bug73462.phpt b/ext/mysqli/tests/bug73462.phpt index 9dfec2a66fd10..6de73761f41a7 100644 --- a/ext/mysqli/tests/bug73462.phpt +++ b/ext/mysqli/tests/bug73462.phpt @@ -10,17 +10,30 @@ require_once('skipifconnectfailure.inc'); query("SHOW STATUS LIKE 'Connections'"); + $c1 = $result->fetch_row(); + $result->free(); $mysql_1->close(); - $mysql_2 = @new mysqli('DOESNT-EXIST', $user, $passwd, $db); + /* Failed connection to invalid host */ + $mysql_2 = @new mysqli(' !!! invalid !!! ', $user, $passwd, $db); @$mysql_2->close(); + /* Re-use persistent connection */ $mysql_3 = new mysqli('p:'.$host, $user, $passwd, $db); $error = mysqli_connect_errno(); + $result = $mysql_3->query("SHOW STATUS LIKE 'Connections'"); + $c3 = $result->fetch_row(); + $result->free(); $mysql_3->close(); - if ($error !== 0) printf("[001] Expecting '0' got '%d'.\n", $error); + if (end($c1) !== end($c3)) + printf("[001] Expected '%d' got '%d'.\n", end($c1), end($c3)); + + if ($error !== 0) + printf("[002] Expected '0' got '%d'.\n", $error); print "done!"; ?>