From 007e650e2e9f4766dd87e1b4757ba14c2694e1b0 Mon Sep 17 00:00:00 2001 From: Ulf Wendel Date: Wed, 10 Oct 2007 10:17:38 +0000 Subject: [PATCH] Adding new tests: mysqli_m*.phpt mysqli_n*.phpt mysqli_o*.phpt mysqli_p*.phpt --- ext/mysqli/tests/mysqli_master_query.phpt | 46 +++++ ext/mysqli/tests/mysqli_max_links.phpt | 72 ++++++++ ext/mysqli/tests/mysqli_more_results.phpt | 110 +++++++++++ ext/mysqli/tests/mysqli_multi_query.phpt | 158 ++++++++++++++++ .../mysqli_mysqli_result_invalid_mode.phpt | 26 +++ ext/mysqli/tests/mysqli_next_result.phpt | 120 ++++++++++++ ext/mysqli/tests/mysqli_no_reconnect.phpt | 111 +++++++++++ ext/mysqli/tests/mysqli_num_fields.phpt | 53 ++++++ ext/mysqli/tests/mysqli_num_rows.phpt | 85 +++++++++ ext/mysqli/tests/mysqli_options.phpt | 115 ++++++++++++ .../tests/mysqli_options_init_command.phpt | 19 ++ .../tests/mysqli_options_openbasedir.phpt | 24 +++ ext/mysqli/tests/mysqli_pconn_disabled.phpt | 63 +++++++ ext/mysqli/tests/mysqli_pconn_kill.phpt | 95 ++++++++++ ext/mysqli/tests/mysqli_pconn_limits.phpt | 96 ++++++++++ ext/mysqli/tests/mysqli_pconn_max_links.phpt | 172 ++++++++++++++++++ ext/mysqli/tests/mysqli_pconn_reuse.phpt | 92 ++++++++++ ext/mysqli/tests/mysqli_pconnect.phpt | 75 ++++++++ ext/mysqli/tests/mysqli_phpinfo.phpt | 73 ++++++++ ext/mysqli/tests/mysqli_ping.phpt | 47 +++++ ext/mysqli/tests/mysqli_prepare.phpt | 121 ++++++++++++ .../tests/mysqli_prepare_no_object.phpt | 43 +++++ 22 files changed, 1816 insertions(+) create mode 100755 ext/mysqli/tests/mysqli_master_query.phpt create mode 100644 ext/mysqli/tests/mysqli_max_links.phpt create mode 100644 ext/mysqli/tests/mysqli_more_results.phpt create mode 100644 ext/mysqli/tests/mysqli_multi_query.phpt create mode 100644 ext/mysqli/tests/mysqli_mysqli_result_invalid_mode.phpt create mode 100644 ext/mysqli/tests/mysqli_next_result.phpt create mode 100644 ext/mysqli/tests/mysqli_no_reconnect.phpt create mode 100644 ext/mysqli/tests/mysqli_num_fields.phpt create mode 100644 ext/mysqli/tests/mysqli_num_rows.phpt create mode 100644 ext/mysqli/tests/mysqli_options.phpt create mode 100644 ext/mysqli/tests/mysqli_options_init_command.phpt create mode 100644 ext/mysqli/tests/mysqli_options_openbasedir.phpt create mode 100644 ext/mysqli/tests/mysqli_pconn_disabled.phpt create mode 100755 ext/mysqli/tests/mysqli_pconn_kill.phpt create mode 100644 ext/mysqli/tests/mysqli_pconn_limits.phpt create mode 100644 ext/mysqli/tests/mysqli_pconn_max_links.phpt create mode 100644 ext/mysqli/tests/mysqli_pconn_reuse.phpt create mode 100644 ext/mysqli/tests/mysqli_pconnect.phpt create mode 100644 ext/mysqli/tests/mysqli_phpinfo.phpt create mode 100644 ext/mysqli/tests/mysqli_ping.phpt create mode 100644 ext/mysqli/tests/mysqli_prepare.phpt create mode 100644 ext/mysqli/tests/mysqli_prepare_no_object.phpt diff --git a/ext/mysqli/tests/mysqli_master_query.phpt b/ext/mysqli/tests/mysqli_master_query.phpt new file mode 100755 index 0000000000..1a0bbac907 --- /dev/null +++ b/ext/mysqli/tests/mysqli_master_query.phpt @@ -0,0 +1,46 @@ +--TEST-- +mysqli_master_query() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: mysqli_master_query(): Couldn't fetch mysqli in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_max_links.phpt b/ext/mysqli/tests/mysqli_max_links.phpt new file mode 100644 index 0000000000..a9a7980229 --- /dev/null +++ b/ext/mysqli/tests/mysqli_max_links.phpt @@ -0,0 +1,72 @@ +--TEST-- +Testing mysqli.max_links +--SKIPIF-- + +--INI-- +mysqli.max_links=1 +--FILE-- + +--EXPECTF-- +bool(true) +int(1) + +Warning: mysqli_connect(): Too many open links (1) in %s on line %d + +Warning: mysqli_connect(): Too many open links (1) in %s on line %d + +Warning: mysqli_connect(): Too many open links (1) in %s on line %d + +Warning: mysqli_connect(): Too many open links (1) in %s on line %d + +Warning: mysqli_connect(): Too many open links (1) in %s on line %d + +Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d + +Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in %s on line %d +done! diff --git a/ext/mysqli/tests/mysqli_more_results.phpt b/ext/mysqli/tests/mysqli_more_results.phpt new file mode 100644 index 0000000000..1f12168841 --- /dev/null +++ b/ext/mysqli/tests/mysqli_more_results.phpt @@ -0,0 +1,110 @@ +--TEST-- +mysqli_more_results() +--SKIPIF-- + +--FILE-- + 41000 && !($ret = mysqli_more_results($link))) + printf("[007] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret); + do { + $res = mysqli_store_result($link); + mysqli_free_result($res); + if (mysqli_more_results($link)) + printf("%d\n", $i++); + } while (mysqli_next_result($link)); + + if ($strict_on) { + $tmp = ob_get_contents(); + ob_end_clean(); + if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) { + printf("[008] Strict Standards warning missing\n"); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + } + + if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3")) + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + print "[010]\n"; + $i = 1; + if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link))) + printf("[011] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret); + + if ($strict_on) + ob_start(); + do { + $res = mysqli_use_result($link); + // NOTE: if you use mysqli_use_result() with mysqli_more_results() or any other info function, + // you must fetch all rows before you can loop to the next result set! + // See also the MySQL Reference Manual: mysql_use_result() + while ($row = mysqli_fetch_array($res)) + ; + mysqli_free_result($res); + if (mysqli_more_results($link)) + printf("%d\n", $i++); + } while (mysqli_next_result($link)); + + if ($strict_on) { + $tmp = ob_get_contents(); + ob_end_clean(); + if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) { + printf("[008] Strict Standards warning missing\n"); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + } + mysqli_close($link); + + var_dump(mysqli_more_results($link)); + + print "done!"; +?> +--EXPECTF-- +[004] +bool(false) +[006] +1 +2 +[010] +1 +2 + +Warning: mysqli_more_results(): Couldn't fetch mysqli in %s on line %d +NULL +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_multi_query.phpt b/ext/mysqli/tests/mysqli_multi_query.phpt new file mode 100644 index 0000000000..f28479bb40 --- /dev/null +++ b/ext/mysqli/tests/mysqli_multi_query.phpt @@ -0,0 +1,158 @@ +--TEST-- +mysqli_multi_query() +--SKIPIF-- + +--FILE-- + $length) + if ($length <= 0) + printf("[017 - %d] Strange column lengths for column %d, got %d expecting any > 0\n", + $res_num, $k, $length); + } + } + + if ($num_rows != 1) + printf("[018 - %d] Expecting 1 row, got %d rows\n", $num_rows); + + $res_num++; + + mysqli_free_result($res); + + } while (@mysqli_next_result($link)); + + if ($res_num != 4) + printf("[015] Expecting 3 result sets got %d result set[s]\n", $res_num); + + mysqli_close($link); + + var_dump(mysqli_multi_query($link, "SELECT id, label FROM test")); + + print "done!"; +?> +--EXPECTF-- +[006] 3 +[008] 0 +[009] [2014] Commands out of sync; you can't run this command now + +[010] 7 + +Warning: mysqli_multi_query(): Couldn't fetch mysqli in %s on line %d +NULL +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_mysqli_result_invalid_mode.phpt b/ext/mysqli/tests/mysqli_mysqli_result_invalid_mode.phpt new file mode 100644 index 0000000000..fd3060c818 --- /dev/null +++ b/ext/mysqli/tests/mysqli_mysqli_result_invalid_mode.phpt @@ -0,0 +1,26 @@ +--TEST-- +mysqli_result(), invalid mode +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: mysqli_result::mysqli_result(): Invalid value for resultmode in %s on line %d +done! diff --git a/ext/mysqli/tests/mysqli_next_result.phpt b/ext/mysqli/tests/mysqli_next_result.phpt new file mode 100644 index 0000000000..118b8677c8 --- /dev/null +++ b/ext/mysqli/tests/mysqli_next_result.phpt @@ -0,0 +1,120 @@ +--TEST-- +mysqli_next_result() +--SKIPIF-- + +--FILE-- += 100; SELECT 1 AS a; ", 11, 1, $strict_on); + + mysqli_close($link); + + var_dump(mysqli_next_result($link)); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_next_result(): Couldn't fetch mysqli in %s on line %d +NULL +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_no_reconnect.phpt b/ext/mysqli/tests/mysqli_no_reconnect.phpt new file mode 100644 index 0000000000..d392b5a1cf --- /dev/null +++ b/ext/mysqli/tests/mysqli_no_reconnect.phpt @@ -0,0 +1,111 @@ +--TEST-- +Trying implicit reconnect after wait_timeout and KILL using mysqli_ping() +--SKIPIF-- + +--INI-- +mysqli.reconnect=0 +--FILE-- + +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_num_fields.phpt b/ext/mysqli/tests/mysqli_num_fields.phpt new file mode 100644 index 0000000000..fc99ecf9e5 --- /dev/null +++ b/ext/mysqli/tests/mysqli_num_fields.phpt @@ -0,0 +1,53 @@ +--TEST-- +mysqli_num_fields() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: mysqli_num_fields(): Couldn't fetch mysqli_result in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_num_rows.phpt b/ext/mysqli/tests/mysqli_num_rows.phpt new file mode 100644 index 0000000000..70af3c4043 --- /dev/null +++ b/ext/mysqli/tests/mysqli_num_rows.phpt @@ -0,0 +1,85 @@ +--TEST-- +mysqli_num_rows() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in %s on line %d + +Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in %s on line %d + +Warning: mysqli_num_rows(): Couldn't fetch mysqli_result in %s on line %d +run_tests.php don't fool me with your 'ungreedy' expression '.+?'! + +Warning: mysqli_num_rows(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_options.phpt b/ext/mysqli/tests/mysqli_options.phpt new file mode 100644 index 0000000000..1bfa5faa3f --- /dev/null +++ b/ext/mysqli/tests/mysqli_options.phpt @@ -0,0 +1,115 @@ +--TEST-- +mysqli_options() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +%s(25) "MYSQLI_READ_DEFAULT_GROUP" +bool(true) +%s(24) "MYSQLI_READ_DEFAULT_FILE" +bool(true) +%s(26) "MYSQLI_OPT_CONNECT_TIMEOUT" +bool(true) +%s(23) "MYSQLI_OPT_LOCAL_INFILE" +bool(true) +%s(19) "MYSQLI_INIT_COMMAND" +bool(true) +%s(25) "MYSQLI_READ_DEFAULT_GROUP" +bool(true) +%s(24) "MYSQLI_READ_DEFAULT_FILE" +bool(true) +%s(26) "MYSQLI_OPT_CONNECT_TIMEOUT" +bool(true) +%s(23) "MYSQLI_OPT_LOCAL_INFILE" +bool(true) +%s(19) "MYSQLI_INIT_COMMAND" +bool(true) +%s(17) "MYSQLI_CLIENT_SSL" +bool(false) +Link closed +Warning: mysqli_options(): Couldn't fetch mysqli in %s line %d +%s(19) "MYSQLI_INIT_COMMAND" +NULL + +Warning: mysqli_options(): Couldn't fetch mysqli in %s line %d +%s(16) "SOME_RANDOM_FLAG" +NULL +done! diff --git a/ext/mysqli/tests/mysqli_options_init_command.phpt b/ext/mysqli/tests/mysqli_options_init_command.phpt new file mode 100644 index 0000000000..667b581753 --- /dev/null +++ b/ext/mysqli/tests/mysqli_options_init_command.phpt @@ -0,0 +1,19 @@ +--TEST-- +mysqli_options() +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +done! diff --git a/ext/mysqli/tests/mysqli_options_openbasedir.phpt b/ext/mysqli/tests/mysqli_options_openbasedir.phpt new file mode 100644 index 0000000000..d5a5bf45ca --- /dev/null +++ b/ext/mysqli/tests/mysqli_options_openbasedir.phpt @@ -0,0 +1,24 @@ +--TEST-- +mysqli_options() - MYSQLI_OPT_LOCAL_INFILE and open_basedir +--SKIPIF-- + +--INI-- +open_basedir="." +--FILE-- + +--EXPECTF-- +done! diff --git a/ext/mysqli/tests/mysqli_pconn_disabled.phpt b/ext/mysqli/tests/mysqli_pconn_disabled.phpt new file mode 100644 index 0000000000..746dd3ba90 --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconn_disabled.phpt @@ -0,0 +1,63 @@ +--TEST-- +mysqli_pconnect() - mysqli.allow_persistent = 0 +--SKIPIF-- + +--INI-- +mysqli.allow_persistent=0 +mysqli.max_persistent=2 +mysqli.max_links=2 +--FILE-- + '%s'\n", $row['_test']); + mysqli_free_result($res); + + if (!$res = mysqli_query($link2, 'SELECT @pcondisabled AS _test')) + printf("[005] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connecction 2 - SELECT @pcondisabled -> '%s'\n", $row['_test']); + mysqli_free_result($res); + + if ($link1 === $link2) + printf("[006] Links should not be identical\n"); + + mysqli_close($link1); + mysqli_close($link2); + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_connect(): Persistent connections are disabled. Downgrading to normal in %s on line %d + +Warning: mysqli_connect(): Persistent connections are disabled. Downgrading to normal in %s on line %d +Connecction 1 - SELECT @pcondisabled -> 'Connection 1' +Connecction 2 - SELECT @pcondisabled -> '' +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pconn_kill.phpt b/ext/mysqli/tests/mysqli_pconn_kill.phpt new file mode 100755 index 0000000000..61d5624515 --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconn_kill.phpt @@ -0,0 +1,95 @@ +--TEST-- +Killing a persistent connection. +--SKIPIF-- + +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +--FILE-- +" from the host variable + $host = substr($host, 2); + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[013] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + if (!$res4 = mysqli_query($link, 'SELECT id FROM test ORDER BY id LIMIT 1')) + printf("[014] New regular connection cannot execute queries, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res4); + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +done! +--UEXPECTF-- +done! diff --git a/ext/mysqli/tests/mysqli_pconn_limits.phpt b/ext/mysqli/tests/mysqli_pconn_limits.phpt new file mode 100644 index 0000000000..774154deeb --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconn_limits.phpt @@ -0,0 +1,96 @@ +--TEST-- +Persistent connections - limits (-1, unlimited) +--SKIPIF-- + +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=-1 +mysqli.max_links=-1 +--FILE-- + +--EXPECTF-- +Regular connection 1 - 'works..' +Regular connection 2 - 'works...' +Persistent connection 1 - 'works...' +Persistent connection 2 - 'works...' +Persistent connection 3 - 'works...' +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pconn_max_links.phpt b/ext/mysqli/tests/mysqli_pconn_max_links.phpt new file mode 100644 index 0000000000..8b47728c1e --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconn_max_links.phpt @@ -0,0 +1,172 @@ +--TEST-- +Persistent connections and mysqli.max_links +--SKIPIF-- + +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +--FILE-- + enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[002] Cannot get # active persistent links from phpinfo()\n"); + $num_plinks = $matches[1]; + + if (!$res = mysqli_query($plink, 'SELECT id, label FROM test WHERE id = 1')) + printf("[003] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysqli_errno($plink), mysqli_error($plink)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[004] Cannot run fetch result, [%d] %s\n", + mysqli_errno($plink), mysqli_error($plink)); + mysqli_free_result($res); + var_dump($row); + + // change the password for the second DB user and kill the persistent connection + if (!mysqli_query($link, 'SET PASSWORD FOR pcontest = PASSWORD("newpass")') || + !mysqli_query($link, 'FLUSH PRIVILEGES')) + printf("[005] Cannot change PW of second DB user, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + // persistent connections cannot be closed but only be killed + $pthread_id = mysqli_thread_id($plink); + if (!mysqli_query($link, sprintf('KILL %d', $pthread_id))) + printf("[006] Cannot KILL persistent connection of second DB user, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + // give the server a second to really kill the thread + sleep(1); + + if (!$res = mysqli_query($link, "SHOW FULL PROCESSLIST")) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $running_threads = array(); + while ($row = mysqli_fetch_assoc($res)) + $running_threads[$row['Id']] = $row; + mysqli_free_result($res); + + if (isset($running_threads[$pthread_id])) + printf("[008] Persistent connection has not been killed\n"); + + // this fails and we have 0 (<= $num_plinks) connections + if ($plink = @mysqli_connect('p:' . $host, 'pcontest', 'pcontest', $db, $port, $socket)) + printf("[009] Can connect using the old password, [%d] %s\n", + mysqli_connect_errno($link), mysqli_connect_error($link)); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + $phpinfo = substr($phpinfo, stripos($phpinfo, 'MysqlI Support => enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[010] Cannot get # of active persistent links from phpinfo()\n"); + + $num_plinks_kill = $matches[1]; + if ($num_plinks_kill > $num_plinks) + printf("[011] Expecting Active Persistent Links < %d, got %d\n", $num_plinks, $num_plinks_kill); + + if (!$plink = mysqli_connect('p:' . $host, 'pcontest', 'newpass', $db, $port, $socket)) + printf("[012] Cannot connect using the new password, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + if (!$res = mysqli_query($plink, 'SELECT id, label FROM test WHERE id = 1')) + printf("[013] Cannot run query on persistent connection of second DB user, [%d] %s\n", + mysqli_errno($plink), mysqli_error($plink)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[014] Cannot run fetch result, [%d] %s\n", + mysqli_errno($plink), mysqli_error($plink)); + mysqli_free_result($res); + var_dump($row); + + if ($plink2 = mysqli_connect('p:' . $host, 'pcontest', 'newpass', $db, $port, $socket)) + printf("[015] Can open more persistent connections than allowed, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + $phpinfo = substr($phpinfo, stripos($phpinfo, 'MysqlI Support => enabled'), 500); + if (!preg_match('@Active Persistent Links\s+=>\s+(\d+)@ismU', $phpinfo, $matches)) + printf("[016] Cannot get # of active persistent links from phpinfo()\n"); + + $num_plinks = $matches[1]; + if ($num_plinks > (int)ini_get('mysqli.max_persistent')) + printf("[017] mysqli.max_persistent=%d allows %d open connections!\n", ini_get('mysqli.max_persistent'),$num_plinks); + + mysqli_query($link, 'REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest'); + mysqli_query($link, 'DROP USER pcontest'); + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} + +Warning: mysqli_connect(): Too many open persistent links (%d) in %s on line %d +done! +--UEXPECTF-- +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} + +Warning: mysqli_connect(): Too many open persistent links (%d) in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pconn_reuse.phpt b/ext/mysqli/tests/mysqli_pconn_reuse.phpt new file mode 100644 index 0000000000..4a7e75b72f --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconn_reuse.phpt @@ -0,0 +1,92 @@ +--TEST-- +mysqli_pconnect() - reusing/caching persistent connections +--SKIPIF-- + +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +mysqli.max_links=2 +--FILE-- + '%s'\n", $row['_test']); + mysqli_free_result($res); + + if (!$res = mysqli_query($link2, 'SELECT @pcondisabled AS _test')) + printf("[005] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connection 2 (no reuse) - SELECT @pcondisabled -> '%s'\n", $row['_test']); + $thread_id = mysqli_thread_id($link2); + printf("Connection 2 (no reuse) - Thread ID -> '%s'\n", $thread_id); + mysqli_free_result($res); + + if (!mysqli_query($link2, 'SET @pcondisabled = "Connection 2"')) + printf("[006] Cannot set user variable to check if we got the same persistent connection, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link2)); + + if (!$res = mysqli_query($link2, 'SELECT @pcondisabled AS _test')) + printf("[007] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connection 2 - SELECT @pcondisabled -> '%s'\n", $row['_test']); + mysqli_free_result($res); + + mysqli_close($link2); + + /* reuse of existing persistent connection expected! */ + if (!$link2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[008] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s, [%d] %s\n", + $host, $user, $db, $port, $socket, mysqli_connect_errno(), mysqli_connect_error()); + } + + if (!$res = mysqli_query($link2, 'SELECT @pcondisabled AS _test')) + printf("[009] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connection 2 (reuse) - SELECT @pcondisabled -> '%s'\n", $row['_test']); + $thread_id_reuse = mysqli_thread_id($link2); + printf("Connection 2 (reuse) - Thread ID -> '%s'\n", $thread_id_reuse); + mysqli_free_result($res); + + if ($thread_id != $thread_id_reuse) + printf("[010] Seems as if we have got a new connection, connections should have been cached and reused!\n"); + + mysqli_close($link1); + mysqli_close($link2); + print "done!"; +?> +--EXPECTF-- +Connection 1 - SELECT @pcondisabled -> 'Connection 1' +Connection 2 (no reuse) - SELECT @pcondisabled -> '' +Connection 2 (no reuse) - Thread ID -> '%d' +Connection 2 - SELECT @pcondisabled -> 'Connection 2' +Connection 2 (reuse) - SELECT @pcondisabled -> 'Connection 2' +Connection 2 (reuse) - Thread ID -> '%d' +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_pconnect.phpt b/ext/mysqli/tests/mysqli_pconnect.phpt new file mode 100644 index 0000000000..c499cffbae --- /dev/null +++ b/ext/mysqli/tests/mysqli_pconnect.phpt @@ -0,0 +1,75 @@ +--TEST-- +mysqli_pconnect() +--SKIPIF-- + +--FILE-- + 0) { + do { + $index = mt_rand(0, $num); + } while (!isset($connections[$index]) && $left > 0); + if (mt_rand(0, 1) > 0) { + $left--; + mysqli_close($connections[$index]); + unset($connections[$index]); + } else { + $left--; + if (!$connections[$index] = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + } + flush(); + } + + while (count($connections)) { + do { + $index = mt_rand(0, $num); + } while (!isset($connections[$index])); + mysqli_close($connections[$index]); + unset($connections[$index]); + } + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_phpinfo.phpt b/ext/mysqli/tests/mysqli_phpinfo.phpt new file mode 100644 index 0000000000..14fdfcd650 --- /dev/null +++ b/ext/mysqli/tests/mysqli_phpinfo.phpt @@ -0,0 +1,73 @@ +--TEST-- +phpinfo() mysqli section +--SKIPIF-- + +--FILE-- + $entry) + if (!stristr($phpinfo, $entry)) + printf("[010] Could not find entry for '%s'\n", $entry); + } + + print "done!"; +?> +--EXPECTF-- +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_ping.phpt b/ext/mysqli/tests/mysqli_ping.phpt new file mode 100644 index 0000000000..ff55bc29f5 --- /dev/null +++ b/ext/mysqli/tests/mysqli_ping.phpt @@ -0,0 +1,47 @@ +--TEST-- +mysqli_ping() +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +bool(true) + +Warning: mysqli_ping(): Couldn't fetch mysqli in %s on line %d +done! \ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_prepare.phpt b/ext/mysqli/tests/mysqli_prepare.phpt new file mode 100644 index 0000000000..4aa671d71a --- /dev/null +++ b/ext/mysqli/tests/mysqli_prepare.phpt @@ -0,0 +1,121 @@ +--TEST-- +mysqli_prepare() +--SKIPIF-- + +--FILE-- + ?'))) + printf("[005] Expecting boolean/false, got %s, [%d] %s\n", gettype($tmp), mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + + if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id FROM test'))) || !mysqli_stmt_execute($stmt)) + printf("[006][%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + + if (!mysqli_query($link, "DROP TABLE IF EXISTS test2")) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!is_object(($stmt = mysqli_prepare($link, 'CREATE TABLE test2(id INT) ENGINE =' . $engine))) || !mysqli_stmt_execute($stmt)) + printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + + if (!is_object(($stmt = mysqli_prepare($link, 'INSERT INTO test2(id) VALUES(?)')))) + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $id = 1; + if (!mysqli_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt)) + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'REPLACE INTO test2(id) VALUES (?)')))) + printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $id = 2; + if (!mysqli_bind_param($stmt, 'i', $id) || !mysqli_stmt_execute($stmt)) + printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'UPDATE test2 SET id = ? WHERE id = ?')))) + printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $id = 3; + $where = 2; + if (!mysqli_bind_param($stmt, 'ii', $id, $where) || !mysqli_stmt_execute($stmt)) + printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'DELETE FROM test2 WHERE id = ?')))) + printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $where = 3; + if (!mysqli_bind_param($stmt, 'i', $where) || !mysqli_stmt_execute($stmt)) + printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'SET @testvar = ?')))) + printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $testvar = 'testvar'; + if (!mysqli_bind_param($stmt, 's', $testvar) || !mysqli_stmt_execute($stmt)) + printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'DO GET_LOCK("testlock", 1)')))) + printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_stmt_close($stmt); + + if (!is_object(($stmt = mysqli_prepare($link, 'SELECT id, @testvar FROM test2')))) + printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $id = $testvar = null; + if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_bind_result($stmt, $id, $testvar)) + printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + while (mysqli_stmt_fetch($stmt)) { + if (('testvar' !== $testvar) || (1 !== $id)) + printf("[022] Expecting 'testvar'/1, got %s/%s. [%d] %s\n", + $testvar, $id, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + } + + var_dump(mysqli_stmt_prepare($stmt, 'SELECT 1; SELECT 2')); + + mysqli_stmt_close($stmt); + + if (!is_null($tmp = @mysqli_stmt_prepare($link, 'SELECT id FROM test', 'foo'))) + printf("[023] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (!is_null($tmp = @mysqli_stmt_prepare($link, 'SELECT id FROM test'))) + printf("[024] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +bool(false) +done! diff --git a/ext/mysqli/tests/mysqli_prepare_no_object.phpt b/ext/mysqli/tests/mysqli_prepare_no_object.phpt new file mode 100644 index 0000000000..de62b57391 --- /dev/null +++ b/ext/mysqli/tests/mysqli_prepare_no_object.phpt @@ -0,0 +1,43 @@ +--TEST-- +mysqli_prepare() - no object on failure +--SKIPIF-- + +--FILE-- +prepare(false))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); + printf("c) [%d] %s\n", $mysqli->errno, $mysqli->error); + + if (false !== ($tmp = $mysqli->prepare(''))) + printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); + printf("c) [%d] %s\n", $mysqli->errno, $mysqli->error); + + print "done!"; +?> +--EXPECTF-- +a) [1065] Query was empty +b) [1065] Query was empty +c) [1065] Query was empty +c) [1065] Query was empty +done! \ No newline at end of file -- 2.50.1