diff options
| author | Ulf Wendel <uw@php.net> | 2007-10-10 10:17:38 +0000 |
|---|---|---|
| committer | Ulf Wendel <uw@php.net> | 2007-10-10 10:17:38 +0000 |
| commit | 007e650e2e9f4766dd87e1b4757ba14c2694e1b0 (patch) | |
| tree | c7d0ae39b543ed8db0b217086236aef0334e4b51 | |
| parent | 92256befd5e3f0a7a62aebd8b5e8dc8f2c13d707 (diff) | |
| download | php-git-007e650e2e9f4766dd87e1b4757ba14c2694e1b0.tar.gz | |
Adding new tests: mysqli_m*.phpt mysqli_n*.phpt mysqli_o*.phpt mysqli_p*.phpt
22 files changed, 1816 insertions, 0 deletions
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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +if (!function_exists('mysqli_master_query')) { + die("skip mysqli_master_query() not available"); +} +require_once('connect.inc'); +if (!$TEST_EXPERIMENTAL) + die("skip - experimental (= unsupported) feature"); +?> +--FILE-- +<?php + /* NOTE: tests is a stub, but function is deprecated, as long as it does not crash when invoking it... */ + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_master_query())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_master_query($link))) + printf("[002] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + } + + if (!is_bool($tmp = mysqli_master_query($link, 'SELECT 1'))) + printf("[004] Expecting boolean/[true|false] value, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_master_query($link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysqli.max_links=1 +--FILE-- +<?php + require_once("connect.inc"); + require_once("table.inc"); + + // to make sure we have at least one working connection... + var_dump(mysqli_ping($link)); + // to make sure that max_links is really set to one + var_dump((int)ini_get('mysqli.max_links')); + + $links = array(); + for ($i = 1; $i <= 5; $i++) + if ($links[$i] = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[%03d] One link is already open, it should not be possible to open more, [%d] %s, [%d] %s\n", + $i, mysqli_connect_errno(), mysqli_connect_error(), + mysqli_errno($links[$i]), mysqli_error($links[$i])); + + for ($i = 1; $i <= 5; $i++) { + if ($res = mysqli_query($links[$i], 'SELECT id FROM test LIMIT 1')) { + printf("[%03d] Can run query on link %d\n", 5 + $i, $i); + mysqli_free_result($res); + } + mysqli_close($links[$i]); + } + + mysqli_close($link); + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $strict_on = false; + if (defined('E_STRICT')) { + error_reporting(((int)ini_get('error_reporting')) | E_STRICT ); + $strict_on = true; + } + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_more_results())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_more_results($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + print "[004]\n"; + var_dump(mysqli_more_results($link)); + + 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("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + print "[006]\n"; + $i = 1; + + if ($strict_on) + ob_start(); + + if (mysqli_get_server_version($link) > 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $strict_on = false; + if (defined('E_STRICT')) { + error_reporting(((int)ini_get('error_reporting')) | E_STRICT ); + $strict_on = true; + } + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_multi_query())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_multi_query($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (false !== ($tmp = mysqli_multi_query($link, ""))) + printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + 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("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ($strict_on) + ob_start(); + + $i = 0; + do { + $res = mysqli_store_result($link); + while ($row = mysqli_fetch_array($res)) + ; + mysqli_free_result($res); + $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("[005a] Strict Standards warning missing\n"); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + } + + printf("[006] %d\n", $i); + + if (!mysqli_multi_query($link, "ALTER TABLE test MODIFY id INT AUTO_INCREMENT; INSERT INTO test(label) VALUES ('a'); SELECT id, label FROM test ORDER BY id")) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $i = 0; + while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) { + + while ($row = mysqli_fetch_array($res)) + ; + mysqli_free_result($res); + printf("%d/%d\n", $i, mysqli_insert_id($link)); + $i++; + } + printf("[008] %d\n", $i); + + if (!mysqli_multi_query($link, "SELECT id, label FROM test")) + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ($strict_on) + ob_start(); + $i = 0; + while (mysqli_next_result($link) && ($res = mysqli_store_result($link))) { + while ($row = mysqli_fetch_array($res)) + $i++; + mysqli_free_result($res); + } + 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("[009a] Strict Standards warning missing\n"); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + } + printf("[010] %d\n", $i); + + if (!mysqli_multi_query($link, "SELECT 1 AS num, 'a' AS somechar; SELECT 2 AS num, 'a' AS somechar; SELECT 3 AS num, 'a' AS somechar")) + printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $res_num = 1; + do { + if (!$res = mysqli_store_result($link)) { + printf("[012 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link)); + continue; + } + + $num_rows = 0; + while ($row = mysqli_fetch_array($res)) { + + $num_rows++; + if ($row['num'] != $res_num) + printf("[013 - %d] Expecting %s got %s\n", $res_num, $res_num, $row['num']); + if ($row['somechar'] != "a") + printf("[014 - %d] Expecting a got %s\n", $res_num, $row['somechar']); + + if (1 == $num_rows) { + /* simple metadata check */ + if (!($lengths = mysqli_fetch_lengths($res))) + printf("[015 - %d] [%d] %s\n", $res_num, mysqli_errno($link), mysqli_error($link)); + + if (count($lengths) != 2) + printf("[016 - %d] Expecting 2 column lengths got %d [%d] %s\n", $res_num, count($lengths)); + + foreach ($lengths as $k => $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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + require('connect.inc'); + require('table.inc'); + + $valid = array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT); + do { + $mode = mt_rand(-1000, 1000); + } while (in_array($mode, $valid)); + + if (!is_object($res = new mysqli_result($link, $mode))) + printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $strict_on = false; + if (defined('E_STRICT')) { + error_reporting(((int)ini_get('error_reporting')) | E_STRICT ); + $strict_on = true; + } + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_next_result())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_next_result($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if ($strict_on) + ob_start(); + + if (false !== ($tmp = mysqli_next_result($link))) + printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + 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("[003a] Strict Standards warning missing\n"); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + ob_start(); + } + + $res = mysqli_query($link, "SELECT 1 AS res"); + if (false !== ($tmp = mysqli_next_result($link))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + 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("[004a] 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_free_result($res); + + function func_test_mysqli_next_result($link, $query, $offset, $num_results, $strict_on) { + + if (!mysqli_multi_query($link, $query)) + printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); + + $i = 0; + if ($strict_on) + ob_start(); + + do { + if ($res = mysqli_store_result($link)) { + mysqli_free_result($res); + $i++; + } + } while (true === 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("[%03d] Strict Standards warning missing\n", $offset + 1); + } else { + $tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp)); + } + print trim($tmp) . "\n"; + } + + if ($i !== $num_results) { + printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i); + } + + if (mysqli_more_results($link)) + printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3); + + if (!($res = mysqli_query($link, "SELECT 1 AS b"))) { + printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link)); + } else { + mysqli_free_result($res); + } + + } + + func_test_mysqli_next_result($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3", 5, 3, $strict_on); + func_test_mysqli_next_result($link, "SELECT 1 AS a; INSERT INTO test(id, label) VALUES (100, 'y'); SELECT 1 AS a, 2 AS b", 8, 2, $strict_on); + func_test_mysqli_next_result($link, "DELETE FROM test WHERE id >= 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +mysqli.reconnect=0 +--FILE-- +<?php + require_once("connect.inc"); + require_once("table.inc"); + + if (!$link2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[001] Cannot create second database connection, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + $thread_id_timeout = mysqli_thread_id($link); + $thread_id_control = mysqli_thread_id($link2); + + if (!$res = mysqli_query($link2, "SHOW FULL PROCESSLIST")) + printf("[002] Cannot get full processlist, [%d] %s\n", + mysqli_errno($link2), 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[$thread_id_timeout]) || + !isset($running_threads[$thread_id_control])) + printf("[003] Processlist is borked, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link)); + + if (!mysqli_query($link, "SET SESSION wait_timeout = 2")) + printf("[004] Cannot set wait_timeout, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_query($link, "SHOW VARIABLES LIKE 'wait_timeout'")) + printf("[005] Cannot check if wait_timeout has been set, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[006] Cannot get wait_timeout, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + mysqli_free_result($res); + + if ($row['Value'] != 2) + printf("[007] Failed setting the wait_timeout, test will not work, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + // after 2+ seconds the server should kill the connection + sleep(3); + + if (!$res = mysqli_query($link2, "SHOW FULL PROCESSLIST")) + printf("[008] Cannot get full processlist, [%d] %s\n", + mysqli_errno($link2), 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[$thread_id_timeout])) + printf("[009] Server should have killed the timeout connection, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link)); + + if (false !== @mysqli_ping($link)) + printf("[010] Reconnect should not have happened"); + + if ($res = @mysqli_query($link, "SELECT DATABASE() as _dbname")) + printf("[011] Executing a query should not be possible, connection should be closed, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + if (!$link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[012] Cannot create database connection, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + $thread_id_timeout = mysqli_thread_id($link); + if (!mysqli_query($link, sprintf('KILL %d', $thread_id_timeout))) + printf("[013] Cannot KILL timeout connection, [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + // Give the server a second to really kill the other thread... + sleep(1); + + if (!$res = mysqli_query($link2, "SHOW FULL PROCESSLIST")) + printf("[014] Cannot get full processlist, [%d] %s\n", + mysqli_errno($link2), 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[$thread_id_timeout]) || + !isset($running_threads[$thread_id_control])) + printf("[015] Processlist is borked, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link)); + + if (false !== ($tmp = @mysqli_ping($link))) + printf("[016] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp); + + if ($res = @mysqli_query($link, "SELECT DATABASE() as _dbname")) + printf("[017] Running a query should not be possible, connection should be gone, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + mysqli_close($link2); + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_num_fields())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_num_fields($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + function func_test_mysqli_num_fields($link, $query, $expected, $offset, $test_free = false) { + + if (!($res = mysqli_query($link, $query))) { + printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); + return; + } + + if ($expected !== ($tmp = mysqli_num_fields($res))) + printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1, + gettype($expected), $expected, + gettype($tmp), $tmp); + + mysqli_free_result($res); + + if ($test_free && (NULL !== ($tmp = mysqli_num_fields($res)))) + printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp); + } + + func_test_mysqli_num_fields($link, "SELECT 1 AS a", 1, 5); + func_test_mysqli_num_fields($link, "SELECT id, label FROM test", 2, 10); + func_test_mysqli_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15); + func_test_mysqli_num_fields($link, "SELECT id FROM test", 1, 20, true); + + mysqli_close($link); + + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_num_rows())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_num_rows($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + function func_test_mysqli_num_rows($link, $query, $expected, $offset, $test_free = false) { + + if (!$res = mysqli_query($link, $query, MYSQLI_STORE_RESULT)) { + printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link)); + return; + } + + if ($expected !== ($tmp = mysqli_num_rows($res))) + printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1, + gettype($expected), $expected, + gettype($tmp), $tmp); + + mysqli_free_result($res); + + if ($test_free && (NULL !== ($tmp = mysqli_num_rows($res)))) + printf("[%03d] Expecting NULL, got %s/%s\n", $offset + 2, gettype($tmp), $tmp); + + } + + func_test_mysqli_num_rows($link, "SELECT 1 AS a", 1, 5); + func_test_mysqli_num_rows($link, "SHOW VARIABLES LIKE '%nixnutz%'", 0, 10); + func_test_mysqli_num_rows($link, "INSERT INTO test(id, label) VALUES (100, 'z')", NULL, 15); + func_test_mysqli_num_rows($link, "SELECT id FROM test LIMIT 2", 2, 20, true); + + if ($res = mysqli_query($link, 'SELECT COUNT(id) AS num FROM test')) { + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + + func_test_mysqli_num_rows($link, "SELECT id, label FROM test", (int)$row['num'], 25); + + } else { + printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + print "run_tests.php don't fool me with your 'ungreedy' expression '.+?'!\n"; + + if ($res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_USE_RESULT)) { + + $row = mysqli_fetch_row($res); + if (0 !== ($tmp = mysqli_num_rows($res))) + printf("[031] Expecting int/0, got %s/%d\n", gettype($tmp), $tmp); + + mysqli_free_result($res); + + } else { + printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + mysqli_close($link); + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + $valid_options = array( MYSQLI_READ_DEFAULT_GROUP, MYSQLI_READ_DEFAULT_FILE, + MYSQLI_OPT_CONNECT_TIMEOUT, MYSQLI_OPT_LOCAL_INFILE, + MYSQLI_INIT_COMMAND, MYSQLI_READ_DEFAULT_GROUP, + MYSQLI_READ_DEFAULT_FILE, MYSQLI_OPT_CONNECT_TIMEOUT, + MYSQLI_OPT_LOCAL_INFILE, MYSQLI_INIT_COMMAND, + MYSQLI_SET_CHARSET_NAME); + + if ($IS_MYSQLND && defined('MYSQLI_OPT_NET_CMD_BUFFER_SIZE')) + $valid_options[] = constant('MYSQLI_OPT_NET_CMD_BUFFER_SIZE'); + if ($IS_MYSQLND && defined('MYSQLI_OPT_NET_READ_BUFFER_SIZE')) + $valid_options[] = constant('MYSQLI_OPT_NET_READ_BUFFER_SIZE'); + if ($IS_MYSQLND && defined('MYSQLI_OPT_INT_AND_YEARS_AS_INT')) + $valid_options[] = constant('MYSQLI_OPT_INT_AND_YEARS_AS_INT'); + if (defined('MYSQLI_OPT_NUMERIC_AND_DATETIME_AS_UNICODE')) + $valid_options[] = constant('MYSQLI_OPT_NUMERIC_AND_DATETIME_AS_UNICODE'); + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_options())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_options($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + $link = mysqli_init(); + + if (!is_null($tmp = @mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_options($link, "s", 'extra_my.cnf'))) + printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT=0', 'foo'))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + // print "run_tests.php don't fool me with your 'ungreedy' expression '.+?'!\n"; + var_dump("MYSQLI_READ_DEFAULT_GROUP", mysqli_options($link, MYSQLI_READ_DEFAULT_GROUP, 'extra_my.cnf')); + var_dump("MYSQLI_READ_DEFAULT_FILE", mysqli_options($link, MYSQLI_READ_DEFAULT_FILE, 'extra_my.cnf')); + var_dump("MYSQLI_OPT_CONNECT_TIMEOUT", mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10)); + var_dump("MYSQLI_OPT_LOCAL_INFILE", mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1)); + var_dump("MYSQLI_INIT_COMMAND", mysqli_options($link, MYSQLI_INIT_COMMAND, array('SET AUTOCOMMIT=0', 'SET AUTOCOMMIT=1'))); + var_dump("MYSQLI_READ_DEFAULT_GROUP", mysqli_options($link, MYSQLI_READ_DEFAULT_GROUP, 'extra_my.cnf')); + var_dump("MYSQLI_READ_DEFAULT_FILE", mysqli_options($link, MYSQLI_READ_DEFAULT_FILE, 'extra_my.cnf')); + var_dump("MYSQLI_OPT_CONNECT_TIMEOUT", mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10)); + var_dump("MYSQLI_OPT_LOCAL_INFILE", mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1)); + var_dump("MYSQLI_INIT_COMMAND", mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT=0')); + var_dump("MYSQLI_CLIENT_SSL", mysqli_options($link, MYSQLI_CLIENT_SSL, 'not an mysqli_option')); + + if ($IS_MYSQLND && defined('MYSQLI_OPT_INT_AND_YEARS_AS_INT') && + !($tmp = mysqli_options($link, constant('MYSQLI_OPT_INT_AND_YEARS_AS_INT'), true))) + printf("[006] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); + + if (defined('MYSQLI_OPT_NUMERIC_AND_DATETIME_AS_UNICODE') && + !($tmp = mysqli_options($link, constant('MYSQLI_OPT_NUMERIC_AND_DATETIME_AS_UNICODE'), true))) + printf("[006] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); + + for ($flag = -10000; $flag < 10000; $flag++) { + if (in_array($flag, $valid_options)) + continue; + if (FALSE !== ($tmp = mysqli_options($link, $flag, 'definetely not an mysqli_option'))) { + var_dump("SOME_FLAG", $flag, $tmp); + } + } + + mysqli_close($link); + + echo "Link closed"; + var_dump("MYSQLI_INIT_COMMAND", mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT=1')); + var_dump("SOME_RANDOM_FLAG", mysqli_options($link, $flag, 'definetly not an mysqli_option')); + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +die("skip - STUB - TODO - this is a stub to remind me that we should also actually test the options"); +?> +<?php require_once('skipifemb.inc'); ?> +--FILE-- +<?php + /* see mysqli.c for details */ + include "connect.inc"; + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--INI-- +open_basedir="." +--FILE-- +<?php + require_once('connect.inc'); + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[001] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + + if (false !== mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, 1)) + printf("[002] Can set MYSQLI_OPT_LOCAL_INFILE although open_basedir is set!\n"); + + mysqli_close($link); + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +if (!stristr(mysqli_get_client_info(), 'mysqlnd')) + die("skip: only available in mysqlnd"); +?> +--INI-- +mysqli.allow_persistent=0 +mysqli.max_persistent=2 +mysqli.max_links=2 +--FILE-- +<?php + include "connect.inc"; + + $host = 'p:' . $host; + if (!$link1 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + // automatic downgrade to normal connections has failed + printf("[001] 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 (!mysqli_query($link1, 'SET @pcondisabled = "Connection 1"')) + printf("[002] Cannot set user variable to check if we got the same persistent connection, [%d] %s\n", + mysqli_errno($link1), mysqli_error($link1)); + + if (!$link2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + // automatic downgrade to normal connections has failed + printf("[003] 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($link1, 'SELECT @pcondisabled AS _test')) + printf("[004] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connecction 1 - SELECT @pcondisabled -> '%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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +require_once("connect.inc"); +if (!$IS_MYSQLND) + die("skip mysqlnd test only"); +?> +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +--FILE-- +<?php + require_once("connect.inc"); + require_once("table.inc"); + + $host = 'p:' . $host; + if (!$plink = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + + // get the thread ids of the two connections... + $thread_id = mysqli_thread_id($link); + $pthread_id = mysqli_thread_id($plink); + + if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST')) + printf("[002] Cannot get processlist, [%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 (count($running_threads) < 2) + printf("[003] Processlist is too short, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!isset($running_threads[$thread_id])) + printf("[004] Cannot find thread id of the regular link, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!isset($running_threads[$pthread_id])) + printf("[005] Cannot find thread id of the persistent link, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + // Kill the persistent connection - don't use mysqli_kill, mysqlnd will catch that... + if (!mysqli_query($link, sprintf('KILL %d', $pthread_id))) + printf("[006] Cannot kill persistent connection, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_close($plink); + // Give the server think-time to kill the pthread + sleep(1); + + if (!$res = mysqli_query($link, 'SHOW FULL PROCESSLIST')) + printf("[007] Cannot get processlist, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $running_threads2 = array(); + while ($row = mysqli_fetch_assoc($res)) + $running_threads2[$row['Id']] = $row; + mysqli_free_result($res); + + if (isset($running_threads2[$pthread_id])) + printf("[008] Thread of the persistent connection should have been gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + if (!isset($running_threads2[$thread_id])) + printf("[009] Thread of the regular connection should be still there, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + // On PHP side this should do nothing. PHP should not try to close the connection or something. + @mysqli_close($plink); + + if (!$plink = @mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + if (!$res3 = @mysqli_query($plink, 'SELECT id FROM test ORDER BY id LIMIT 1')) { + printf("[012] New persistent connection cannot execute queries, [%d] %s\n", @mysqli_errno($plink), @mysqli_error($plink)); + } + + @mysqli_free_result($res3); + @mysqli_close($plink); + mysqli_close($link); + + // remove the "p:<host>" 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +require_once("connect.inc"); +if (!$IS_MYSQLND) + die("skip mysqlnd test only"); +?> +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=-1 +mysqli.max_links=-1 +--FILE-- +<?php + require_once("connect.inc"); + // opens a regular connection + require_once("table.inc"); + + if (!$res = mysqli_query($link, 'SELECT "works.." as _desc')) + printf("[001] Cannot run query, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + printf("Regular connection 1 - '%s'\n", $row['_desc']); + + if (!$link2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[002] Cannot open second regular connection, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + if (!$res = mysqli_query($link2, 'SELECT "works..." as _desc')) + printf("[003] Cannot run query, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + printf("Regular connection 2 - '%s'\n", $row['_desc']); + + $host = 'p:' . $host; + if (!$plink = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[004] Cannot create persistent connection 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($plink, 'SELECT "works..." as _desc')) + printf("[005] Cannot run query, [%d] %s\n", + mysqli_errno($plink), mysqli_error($plink)); + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + printf("Persistent connection 1 - '%s'\n", $row['_desc']); + + if (!$plink2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[006] Cannot create persistent connection 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($plink2, 'SELECT "works..." as _desc')) + printf("[007] Cannot run query, [%d] %s\n", + mysqli_errno($plink2), mysqli_error($plink2)); + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + printf("Persistent connection 2 - '%s'\n", $row['_desc']); + + $plink3 = mysqli_init(); + if (!mysqli_real_connect($plink3, $host, $user, $passwd, $db, $port, $socket)) + printf("[008] Cannot create persistent connection 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($plink3, 'SELECT "works..." as _desc')) + printf("[009] Cannot run query, [%d] %s\n", + mysqli_errno($plink2), mysqli_error($plink2)); + + $row = mysqli_fetch_assoc($res); + mysqli_free_result($res); + printf("Persistent connection 3 - '%s'\n", $row['_desc']); + + mysqli_close($link); + mysqli_close($link2); + mysqli_close($plink); + mysqli_close($plink2); + mysqli_close($plink3); + print "done!"; +?> +--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-- +<?php + require_once('skipif.inc'); + require_once('skipifemb.inc'); + require_once('skipifconnectfailure.inc'); + require_once('connect.inc'); + + if (!$IS_MYSQLND) + die("skip mysqlnd only test"); + + // we need a second DB user to test for a possible flaw in the ext/mysql[i] code + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + die(sprintf("skip Cannot connect [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); + + mysqli_query($link, 'DROP USER pcontest'); + if (!mysqli_query($link, 'CREATE USER pcontest IDENTIFIED BY "pcontest"')) { + printf("skip Cannot create second DB user [%d] %s", mysqli_errno($link), mysqli_error($link)); + mysqli_close($link); + die(); + } + + // we might be able to specify the host using CURRENT_USER(), but... + if (!mysqli_query($link, sprintf("GRANT SELECT ON TABLE %s.test TO pcontest@'%%'", $db))) { + printf("skip Cannot GRANT SELECT to second DB user [%d] %s", mysqli_errno($link), mysqli_error($link)); + mysqli_query($link, 'REVOKE ALL PRIVILEGES, GRANT OPTION FROM pcontest'); + mysqli_query($link, 'DROP USER pcontest'); + mysqli_close($link); + die(); + } + mysqli_close($link); +?> +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +--FILE-- +<?php + require_once("connect.inc"); + require_once('table.inc'); + + if (!$plink = mysqli_connect('p:' . $host, 'pcontest', 'pcontest', $db, $port, $socket)) + printf("[001] Cannot connect using the second DB user created during SKIPIF, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error()); + + ob_start(); + phpinfo(); + $phpinfo = strip_tags(ob_get_contents()); + ob_end_clean(); + + $phpinfo = substr($phpinfo, strpos($phpinfo, 'MysqlI Support => 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +if (!stristr(mysqli_get_client_info(), 'mysqlnd')) + die("skip: only available in mysqlnd"); +?> +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=2 +mysqli.max_links=2 +--FILE-- +<?php + include "connect.inc"; + + $host = 'p:' . $host; + if (!$link1 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[001] 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 (!mysqli_query($link1, 'SET @pcondisabled = "Connection 1"')) + printf("[002] Cannot set user variable to check if we got the same persistent connection, [%d] %s\n", + mysqli_errno($link1), mysqli_error($link1)); + + if (!$link2 = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + printf("[003] 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($link1, 'SELECT @pcondisabled AS _test')) + printf("[004] [%d] %s\n", mysqli_errno($link2), mysqli_error($link2)); + + $row = mysqli_fetch_assoc($res); + printf("Connection 1 - SELECT @pcondisabled -> '%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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +if (!stristr(mysqli_get_client_info(), 'mysqlnd')) + die("skip: only available in mysqlnd"); +?> +--FILE-- +<?php + include "connect.inc"; + + $host = 'p:' . $host; + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + + mysqli_close($link); + + $num = 20; + $connections = array(); + for ($i = 0; $i < $num; $i++) { + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[003] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $connections[] = $link; + } + while (count($connections)) { + do { + $index = mt_rand(0, $num); + } while (!isset($connections[$index])); + mysqli_close($connections[$index]); + unset($connections[$index]); + } + + + $connections = array(); + $num = 20; + for ($i = 0; $i < $num; $i++) { + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[004] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $connections[] = $link; + } + $left = $num; + + while (count($connections) && $left > 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include("connect.inc"); + + @ob_clean(); + ob_start(); + phpinfo(); + $phpinfo = ob_get_contents(); + ob_end_clean(); + + /* all versions should at least dump this minimum information */ + if (!stristr($phpinfo, "mysqli support")) + printf("[001] ext/mysqli should have exposed itself.\n"); + + if (!stristr($phpinfo, "client api library version")) + printf("[002] ext/mysqli should have exposed the library version.\n"); + + if (!stristr($phpinfo, "mysqli.default_host")) + printf("[003] php.ini setting mysqli.default_host not shown.\n"); + + if (!stristr($phpinfo, "mysqli.default_port")) + printf("[004] php.ini setting mysqli.default_port not shown.\n"); + + if (!stristr($phpinfo, "mysqli.default_pw")) + printf("[005] php.ini setting mysqli.default_pw not shown.\n"); + + if (!stristr($phpinfo, "mysqli.default_socket")) + printf("[006] php.ini setting mysqli.default_socket not shown.\n"); + + if (!stristr($phpinfo, "mysqli.default_user")) + printf("[007] php.ini setting mysqli.default_user not shown.\n"); + + if (!stristr($phpinfo, "mysqli.max_links")) + printf("[008] php.ini setting mysqli.max_links not shown.\n"); + + if (!stristr($phpinfo, "mysqli.reconnect")) + printf("[009] php.ini setting mysqli.reconnect not shown.\n"); + + if ($IS_MYSQLND) { + $expected = array( + 'client statistics', + 'bytes_sent', 'bytes_received', 'packets_sent', 'packets_received', + 'protocol_overhead_in', 'protocol_overhead_out', 'result_set_queries', + 'non_result_set_queries', 'no_index_used', 'bad_index_used', + 'buffered_sets', 'unbuffered_sets', 'ps_buffered_sets', 'ps_unbuffered_sets', + 'flushed_normal_sets', 'flushed_ps_sets', 'rows_fetched_from_server', + 'rows_fetched_from_client', 'rows_skipped', 'copy_on_write_saved', + 'copy_on_write_performed', 'command_buffer_too_small', 'connect_success', + 'connect_failure', 'connection_reused', 'explicit_close', 'implicit_close', + 'disconnect_close', 'in_middle_of_command_close', 'explicit_free_result', + 'implicit_free_result', 'explicit_stmt_close', 'implicit_stmt_close', + 'put_hits', 'put_misses', 'get_hits', 'get_misses', + 'size', 'free_items', 'references', 'mysqli.cache_size', + 'mysqli.allow_local_infile', + 'mysqli.allow_persistent', 'mysqli.max_persistent' + ); + foreach ($expected as $k => $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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_ping())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (!is_null($tmp = @mysqli_ping($link, $link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + var_dump(mysqli_ping($link)); + + // provoke an error to check if mysqli_ping resets it + $res = mysqli_query($link, 'SELECT * FROM unknown_table'); + if (!($errno = mysqli_errno($link))) + printf("[003] Statement should have caused an error\n"); + + var_dump(mysqli_ping($link)); + if ($errno === mysqli_errno($link)) + printf("[004] Error codes should have been reset\n"); + + mysqli_close($link); + + if (!is_null($tmp = mysqli_ping($link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_prepare())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_prepare($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (false !== ($tmp = @mysqli_prepare($link, false))) + printf("[003] Expecting boolean/false, got %s\n", gettype($tmp)); + + if (!$res = mysqli_query($link, "SELECT id, label FROM test", MYSQLI_USE_RESULT)) + printf("[004] [%d] %s, next test will fail\n", mysqli_errno($link), mysqli_error($link)); + + if (false !== ($tmp = mysqli_prepare($link, 'SELECT id FROM test WHERE id > ?'))) + 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-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + require('table.inc'); + + if (false !== ($tmp = mysqli_prepare($link, false))) + printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); + printf("a) [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (false !== ($tmp = mysqli_prepare($link, ''))) + printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); + printf("b) [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_close($link); + + if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket)) + printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket); + + if (false !== ($tmp = $mysqli->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 |
