diff options
author | Ulf Wendel <uw@php.net> | 2007-10-10 10:18:29 +0000 |
---|---|---|
committer | Ulf Wendel <uw@php.net> | 2007-10-10 10:18:29 +0000 |
commit | 5ec98ed1c8b9b9a55dd3c401dace378c0d045077 (patch) | |
tree | 8023bd8da40ec1bf1e1f25cde19cdfcb9450892b /ext | |
parent | 007e650e2e9f4766dd87e1b4757ba14c2694e1b0 (diff) | |
download | php-git-5ec98ed1c8b9b9a55dd3c401dace378c0d045077.tar.gz |
Adding new tests: mysqli_q*.phpt mysqli_r*.phpt
Diffstat (limited to 'ext')
25 files changed, 2592 insertions, 0 deletions
diff --git a/ext/mysqli/tests/mysqli_query.phpt b/ext/mysqli/tests/mysqli_query.phpt new file mode 100644 index 0000000000..18f65e2371 --- /dev/null +++ b/ext/mysqli/tests/mysqli_query.phpt @@ -0,0 +1,140 @@ +--TEST-- +mysqli_query() +--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_query())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_query($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (false !== ($tmp = @mysqli_query($link, ''))) + printf("[002a] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_query($link, "SELECT 1 AS a", MYSQLI_USE_RESULT, "foo"))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_query($link, 'THIS IS NOT SQL'))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_query($link, 'SELECT "this is sql but with backslash g"\g'))) + printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link))) + printf("[006] mysqli_errno()/mysqli_error should return some error\n"); + + if (!$res = mysqli_query($link, 'SELECT "this is sql but with semicolon" AS valid ; ')) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + + if (!$res = mysqli_query($link, 'SELECT "a" AS ""')) + printf("[007a] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + var_dump($tmp = mysqli_fetch_assoc($res)); + var_dump($tmp[""]); + mysqli_free_result($res); + + if (false !== ($res = mysqli_query($link, 'SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES'))) + printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_get_server_version($link) > 50000) { + // let's try to play with stored procedures + mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'); + if (mysqli_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) { + $res = mysqli_query($link, 'CALL p(@version)'); + $res = mysqli_query($link, 'SELECT @version AS p_version'); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || ('' == $tmp['p_version'])) { + printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + mysqli_query($link, 'DROP FUNCTION IF EXISTS f'); + if (mysqli_query($link, 'CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;')) { + $res = mysqli_query($link, 'SELECT f(VERSION()) AS f_version'); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['f_version']) || ('' == $tmp['f_version'])) { + printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + } + + if (!is_object($res = mysqli_query($link, "SELECT id FROM test ORDER BY id", MYSQLI_USE_RESULT))) + printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_free_result($res); + + if (!is_object($res = mysqli_query($link, "SELECT id FROM test ORDER BY id", MYSQLI_STORE_RESULT))) + printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + mysqli_free_result($res); + + $valid = array(MYSQLI_USE_RESULT, MYSQLI_STORE_RESULT); + do { + $mode = mt_rand(-1000, 1000); + } while (in_array($mode, $valid)); + + if (false !== ($res = @mysqli_query($link, "SELECT id FROM test ORDER BY id", $mode))) + printf("[013] Invalid mode should return false got %s/%s, [%d] %s\n", + gettype($res), (is_object($res)) ? 'object' : $res, + mysqli_errno($link), mysqli_error($link)); + + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_query($link, "SELECT id FROM test"))) + printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +array(1) { + ["valid"]=> + string(30) "this is sql but with semicolon" +} +array(1) { + [""]=> + string(1) "a" +} +string(1) "a" + +Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d +done! +--UEXPECTF-- +array(1) { + [u"valid"]=> + unicode(30) "this is sql but with semicolon" +} +array(1) { + [u""]=> + unicode(1) "a" +} +unicode(1) "a" + +Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_query_stored_proc.phpt b/ext/mysqli/tests/mysqli_query_stored_proc.phpt new file mode 100644 index 0000000000..051b541fdb --- /dev/null +++ b/ext/mysqli/tests/mysqli_query_stored_proc.phpt @@ -0,0 +1,212 @@ +--TEST-- +mysqli_query() - Stored Procedures +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +require_once('connect.inc'); +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error())); +} +if (mysqli_get_server_version($link) <= 50000) { + die(sprintf('skip Needs MySQL 5.0+, found version %d.', mysqli_get_server_version($link))); +} +?> +--FILE-- +<?php + require_once('connect.inc'); + require_once('table.inc'); + + if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) + printf("[001] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_query($link, 'CREATE PROCEDURE p() READS SQL DATA BEGIN SELECT id, label FROM test ORDER BY id ASC; +END;')) { + /* stored proc which returns one result set */ + if (mysqli_multi_query($link, 'CALL p()')) { + do { + if ($res = mysqli_use_result($link)) { + // skip results, don't fetch all from server + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + } + } while (mysqli_more_results($link) && mysqli_next_result($link)); + + } else { + printf("[003] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + if (mysqli_multi_query($link, 'CALL p()')) { + do { + if ($res = mysqli_store_result($link)) { + // fetch all results from server, but skip on client side + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + } + } while (mysqli_more_results($link) && mysqli_next_result($link)); + + } else { + printf("[004] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + if (mysqli_multi_query($link, 'CALL p()')) { + do { + if ($res = mysqli_store_result($link)) { + // fetch all results from server, but skip on client side + var_dump(mysqli_fetch_assoc($res)); + while (mysqli_fetch_assoc($res)) + ; + mysqli_free_result($res); + } + } while (mysqli_more_results($link) && mysqli_next_result($link)); + + } else { + printf("[005] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + } else { + printf("[002] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + } + + if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) + printf("[006] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_query($link, 'CREATE PROCEDURE p() READS SQL DATA BEGIN SELECT id, label FROM test ORDER BY id ASC; SELECT id FROM test ORDER BY id ASC; END;')) { + /* stored proc which returns two result sets */ + + if (mysqli_multi_query($link, 'CALL p()')) { + do { + if ($res = mysqli_store_result($link)) { + // fetch all results from server, but skip on client side + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + } + } while (mysqli_more_results($link) && mysqli_next_result($link)); + + } else { + printf("[008] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + } else { + printf("[007] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + } + + if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) + printf("[009] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) { + /* no result set, just output parameter */ + if (!mysqli_query($link, 'CALL p(@version)')) + printf("[011] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'SET @version = "unknown"')) + printf("[012] Cannot reset user variable, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'CALL p(@version)')) + printf("[013] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_query($link, 'SELECT @version as _vers')) + printf("[014] Cannot fetch user variable, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res) || + $row['_vers'] == 'unknown') + printf("[015] Results seem wrong, got %s, [%d] %s\n", + $row['_vers'], + mysqli_errno($link), mysqli_error($link)); + mysqli_free_result($res); + + } else { + printf("[010] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + } + + if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) + printf("[016] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) { + /* no result set, one input, one output parameter */ + if (!mysqli_query($link, 'CALL p("myversion", @version)')) + printf("[018] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'SET @version = "unknown"')) + printf("[019] Cannot reset user variable, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'CALL p("myversion", @version)')) + printf("[020] Cannot call SP, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_query($link, 'SELECT @version as _vers')) + printf("[021] Cannot fetch user variable, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res) || + $row['_vers'] == 'myversion') + printf("[022] Results seem wrong, got %s, [%d] %s\n", + $row['_vers'], + mysqli_errno($link), mysqli_error($link)); + mysqli_free_result($res); + + } else { + printf("[017] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); + } + + 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" +} +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +array(2) { + ["id"]=> + string(1) "1" + ["label"]=> + string(1) "a" +} +array(1) { + ["id"]=> + string(1) "1" +} +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" +} +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +array(2) { + [u"id"]=> + unicode(1) "1" + [u"label"]=> + unicode(1) "a" +} +array(1) { + [u"id"]=> + unicode(1) "1" +} +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_query_unicode.phpt b/ext/mysqli/tests/mysqli_query_unicode.phpt new file mode 100644 index 0000000000..3b2a3dd710 --- /dev/null +++ b/ext/mysqli/tests/mysqli_query_unicode.phpt @@ -0,0 +1,141 @@ +--TEST-- +mysqli_query() - unicode (cyrillic) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +require_once('connect.inc'); +require_once('table.inc'); +if (!$res = mysqli_query($link, "SHOW CHARACTER SET LIKE 'utf8'")) + die("skip UTF8 chatset seems not available"); +mysqli_free_result($res); +mysqli_close($link); +?> +--FILE-- +<?php + include_once("connect.inc"); + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_query())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_query($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require_once('table.inc'); + + if (TRUE !== ($tmp = @mysqli_query($link, "set names utf8"))) + printf("[002.5] Expecting TRUE, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_query($link, "SELECT 1 AS колона", MYSQLI_USE_RESULT, "foo"))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_query($link, 'това не е ескюел'))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_query($link, 'SELECT "това е ескюел, но със обратна наклонена и g"\g'))) + printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link))) + printf("[006] mysqli_errno()/mysqli_error should return some error\n"); + + if (!$res = mysqli_query($link, 'SELECT "това ескюел, но с точка и запетая" AS правилен ; ')) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + + if (false !== ($res = mysqli_query($link, 'SELECT "това ескюел, но с точка и запетая" AS правилен ; SHOW VARIABLES'))) + printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (mysqli_get_server_version($link) > 50000) { + // let's try to play with stored procedures + mysqli_query($link, 'DROP PROCEDURE IF EXISTS процедурка'); + if (mysqli_query($link, 'CREATE PROCEDURE процедурка(OUT версия VARCHAR(25)) BEGIN SELECT VERSION() INTO версия; END;')) { + $res = mysqli_query($link, 'CALL процедурка(@version)'); + $res = mysqli_query($link, 'SELECT @version AS п_версия'); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['п_версия']) || ('' == $tmp['п_версия'])) { + printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + + mysqli_query($link, 'DROP FUNCTION IF EXISTS функцийка'); + if (mysqli_query($link, 'CREATE FUNCTION функцийка( параметър_версия VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN параметър_версия;')) { + $res = mysqli_query($link, 'SELECT функцийка(VERSION()) AS ф_версия'); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['ф_версия']) || ('' == $tmp['ф_версия'])) { + printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + } + + /* + Trying to test what Ramil suggests in http://bugs.mysql.com/bug.php?id=29576 + However, this won't work, because we're lacking MYSQLI_SET_CHARSET_NAME. + if (ini_get("unicode.semantics")) { + if (mysqli_get_server_version() > 50002) { + @mysqli_query($link, "DROP USER IF EXISTS 'тест'@'%'"); + if (TRUE !== mysqli_query($link, "CREATE USER 'тест'@'%'")) { + var_dump(mysqli_error($link); + } + } + if (TRUE !== mysqli_query($link, "GRANT SELECT ON $db.* TO 'тест'@'%' IDENTIFIED BY 'парола'")) { + var_dump(mysqli_error($link); + } else { + $link2 = mysqli_init(); + if (!(mysqli_real_connect($link2, $host, "тест", 'парола', $db, $port, $socket))) { + printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=парола, dbname=%s, port=%s, socket=%s, [%d] %s\n", + $host, "тест", $db, $port, $socket, + mysqli_connect_errno(), mysqli_connect_error()); + } + mysqli_close($link2); + if (mysqli_get_server_version() > 50002) { + if (!mysqli_query($link, "DROP USER 'тест'@'%'")) + printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } else { + printf("[015] Cannot create user or grant privileges, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + } + } + } + */ + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_query($link, "SELECT id FROM test"))) + printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +array(1) { + ["правилен"]=> + string(59) "това ескюел, но с точка и запетая" +} + +Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d +done! +--UEXPECTF-- +array(1) { + [u"правилен"]=> + unicode(33) "това ескюел, но с точка и запетая" +} + +Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_connect.phpt b/ext/mysqli/tests/mysqli_real_connect.phpt new file mode 100644 index 0000000000..e2050348cf --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_connect.phpt @@ -0,0 +1,173 @@ +--TEST-- +mysqli_real_connect() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include("connect.inc"); + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_real_connect($link))) + printf("[001a] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link))) + printf("[001b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link))) + printf("[001c] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link))) + printf("[001d] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, $link))) + printf("[001e] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, $link, $link))) + printf("[001f] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, $link, $link, $link))) + printf("[001g] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + // ( mysqli link [, string hostname [, string username [, string passwd [, string dbname [, int port [, string socket [, int flags]]]]]]] + if (NULL !== ($tmp = @mysqli_real_connect($link, $link, $link, $link, $link, $link, $link, $link))) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!$link = mysqli_init()) + printf("[002] mysqli_init() failed\n"); + + if (!mysqli_real_connect($link, $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); + + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[004] mysqli_init() failed\n"); + + if (false !== ($tmp = mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))) + printf("[005] Expecting boolean/false got %s/%s. Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", gettype($tmp), $tmp, $host, $user . 'unknown_really', $db, $port, $socket); + + // Run the following tests without an anoynmous MySQL user and use a password for the test user! + ini_set('mysqli.default_socket', $socket); + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port)) { + printf("[006] Usage of mysqli.default_socket failed\n"); + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[007] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_port', $port); + if (!mysqli_real_connect($link, $host, $user, $passwd, $db)) { + printf("[008] Usage of mysqli.default_port failed\n"); + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[009] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_pw', $passwd); + if (!mysqli_real_connect($link, $host, $user)) { + printf("[010] Usage of mysqli.default_pw failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[011] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_user', $user); + if (!mysqli_real_connect($link, $host)) { + printf("[012] Usage of mysqli.default_user failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[011] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_host', $host); + if (!mysqli_real_connect($link)) { + printf("[014] Usage of mysqli.default_host failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[015] mysqli_init() failed\n"); + } + + // CLIENT_MULTI_STATEMENTS - should be disabled silently + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 65536)) + printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ($res = mysqli_query($link, "SELECT 1 AS a; SELECT 2 AS b")) { + printf("[017] Should have failed. CLIENT_MULTI_STATEMENT should have been disabled.\n"); + var_dump($res->num_rows); + mysqli_next_result($link); + $res = mysqli_store_result($link); + var_dump($res->num_rows); + } + + + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[018] mysqli_init() failed\n"); + + if (ini_get('open_basedir')) { + // CLIENT_LOCAL_FILES should be blocked - but how to test it ?! + + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 128)) + printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mysqli_real_connect_phpt'; + if (!$fp = fopen($filename, 'w')) + printf("[020] Cannot open temporary file %s\n", $filename); + + fwrite($fp, '100;z'); + fclose($fp); + + // how do we test if gets forbidden because of a missing right or the flag, this test is partly bogus ? + if (mysqli_query($link, "LOAD DATA LOCAL INFILE '$filename' INTO TABLE test FIELDS TERMINATED BY ';'")) + printf("[021] LOAD DATA INFILE should have been forbidden!\n"); + + unlink($filename); + } + + mysqli_close($link); + + if ($IS_MYSQLND) { + ini_set('mysqli.default_host', 'p:' . $host); + $link = mysqli_init(); + if (!@mysqli_real_connect($link)) { + printf("[022] Usage of mysqli.default_host=p:%s (persistent) failed\n", $host) ; + } else { + if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host (persistent)' AS 'testing'")) + printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + if ($tmp['testing'] !== 'mysqli.default_host (persistent)') { + printf("[024] Result looks strange - check manually, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + mysqli_free_result($res); + mysqli_close($link); + } + + ini_set('mysqli.default_host', 'p:'); + $link = mysqli_init(); + if (@mysqli_real_sconnect($link)) { + printf("[025] Usage of mysqli.default_host=p: did not fail\n") ; + mysqli_close($link); + } + } + + if (NULL !== ($tmp = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))) + printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_real_connect(): (%d/%d): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_connect_pconn.phpt b/ext/mysqli/tests/mysqli_real_connect_pconn.phpt new file mode 100644 index 0000000000..ff7f4eff95 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_connect_pconn.phpt @@ -0,0 +1,152 @@ +--TEST-- +mysqli_real_connect() - persistent connections +--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"); +?> +--INI-- +mysqli.allow_persistent=1 +mysqli.max_persistent=10 +--FILE-- +<?php + require_once("connect.inc"); + $host = 'p:' . $host; + + if (!$link = mysqli_init()) + printf("[002] mysqli_init() failed\n"); + + if (!mysqli_real_connect($link, $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); + + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[004] mysqli_init() failed\n"); + + if (false !== ($tmp = mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))) + printf("[005] Expecting boolean/false got %s/%s. Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", gettype($tmp), $tmp, $host, $user . 'unknown_really', $db, $port, $socket); + + // Run the following tests without an anoynmous MySQL user and use a password for the test user! + ini_set('mysqli.default_socket', $socket); + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port)) { + printf("[006] Usage of mysqli.default_socket failed\n"); + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[007] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_port', $port); + if (!mysqli_real_connect($link, $host, $user, $passwd, $db)) { + printf("[008] Usage of mysqli.default_port failed\n"); + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[009] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_pw', $passwd); + if (!mysqli_real_connect($link, $host, $user)) { + printf("[010] Usage of mysqli.default_pw failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[011] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_user', $user); + if (!mysqli_real_connect($link, $host)) { + printf("[012] Usage of mysqli.default_user failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[011] mysqli_init() failed\n"); + } + + ini_set('mysqli.default_host', $host); + if (!mysqli_real_connect($link)) { + printf("[014] Usage of mysqli.default_host failed\n") ; + } else { + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[015] mysqli_init() failed\n"); + } + + // CLIENT_MULTI_STATEMENTS - should be disabled silently + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 65536)) + printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ($res = mysqli_query($link, "SELECT 1 AS a; SELECT 2 AS b")) { + printf("[017] Should have failed. CLIENT_MULTI_STATEMENT should have been disabled.\n"); + var_dump($res->num_rows); + mysqli_next_result($link); + $res = mysqli_store_result($link); + var_dump($res->num_rows); + } + + + mysqli_close($link); + if (!$link = mysqli_init()) + printf("[018] mysqli_init() failed\n"); + + if (ini_get('open_basedir')) { + // CLIENT_LOCAL_FILES should be blocked - but how to test it ?! + + if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 128)) + printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mysqli_real_connect_phpt'; + if (!$fp = fopen($filename, 'w')) + printf("[020] Cannot open temporary file %s\n", $filename); + + fwrite($fp, '100;z'); + fclose($fp); + + // how do we test if gets forbidden because of a missing right or the flag, this test is partly bogus ? + if (mysqli_query($link, "LOAD DATA LOCAL INFILE '$filename' INTO TABLE test FIELDS TERMINATED BY ';'")) + printf("[021] LOAD DATA INFILE should have been forbidden!\n"); + + unlink($filename); + } + + mysqli_close($link); + + if ($IS_MYSQLND) { + ini_set('mysqli.default_host', 'p:' . $host); + $link = mysqli_init(); + if (!@mysqli_real_connect($link)) { + printf("[022] Usage of mysqli.default_host=p:%s (persistent) failed\n", $host) ; + } else { + if (!$res = mysqli_query($link, "SELECT 'mysqli.default_host (persistent)' AS 'testing'")) + printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + if ($tmp['testing'] !== 'mysqli.default_host (persistent)') { + printf("[024] Result looks strange - check manually, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + mysqli_free_result($res); + mysqli_close($link); + } + + ini_set('mysqli.default_host', 'p:'); + $link = mysqli_init(); + if (@mysqli_real_sconnect($link)) { + printf("[025] Usage of mysqli.default_host=p: did not fail\n") ; + mysqli_close($link); + } + } + + if (NULL !== ($tmp = mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket))) + printf("[026] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_real_connect(): (%d/%d): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string.phpt b/ext/mysqli/tests/mysqli_real_escape_string.phpt new file mode 100644 index 0000000000..b25c72acd8 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string.phpt @@ -0,0 +1,58 @@ +--TEST-- +mysqli_real_escape_string() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_real_escape_string())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_escape_string($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (NULL !== ($tmp =@mysqli_real_escape_string($link, "foo", "foo"))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if ('\\\\' !== ($tmp = mysqli_real_escape_string($link, '\\'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('\"' !== ($tmp = mysqli_real_escape_string($link, '"'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("\'" !== ($tmp = mysqli_real_escape_string($link, "'"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("\\n" !== ($tmp = mysqli_real_escape_string($link, "\n"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("\\r" !== ($tmp = mysqli_real_escape_string($link, "\r"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("foo\\0bar" !== ($tmp = mysqli_real_escape_string($link, "foo" . chr(0) . "bar"))) + printf("[009] Expecting %s, got %s\n", "foo\\0bar", $tmp); + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_real_escape_string($link, 'foo'))) + printf("[010] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + /* Make sure that the function alias exists */ + if (NULL !== ($tmp = @mysqli_escape_string())) + printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_big5.phpt b/ext/mysqli/tests/mysqli_real_escape_string_big5.phpt new file mode 100644 index 0000000000..ea49205611 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_big5.phpt @@ -0,0 +1,54 @@ +--TEST-- +mysqli_real_escape_string() - big5 +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'big5')) + die(sprintf("skip Cannot set charset 'big5'")); +mysqli_close($link); +?> +--FILE-- +<?php + + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "big5")); + + if ('HUe\\\\HUe' !== ($tmp = mysqli_real_escape_string($link, 'HUe\\HUe'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('HUe\"HUe' !== ($tmp = mysqli_real_escape_string($link, 'HUe"HUe'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("HUe\'HUe" !== ($tmp = mysqli_real_escape_string($link, "HUe'HUe"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("HUe\\nHUe" !== ($tmp = mysqli_real_escape_string($link, "HUe\nHUe"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("HUe\\rHUe" !== ($tmp = mysqli_real_escape_string($link, "HUe\rHUe"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("HUe\\0HUe" !== ($tmp = mysqli_real_escape_string($link, "HUe" . chr(0) . "HUe"))) + printf("[009] Expecting %s, got %s\n", "HUe\\0HUe", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_eucjpms.phpt b/ext/mysqli/tests/mysqli_real_escape_string_eucjpms.phpt new file mode 100644 index 0000000000..ef9c3f065e --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_eucjpms.phpt @@ -0,0 +1,53 @@ +--TEST-- +mysqli_real_escape_string() - eucjpms +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'eucjpms')) + die(sprintf("skip Cannot set charset 'eucjpms'")); +mysqli_close($link); +?> +--FILE-- +<?php + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "eucjpms")); + + if ('Ȥ߹碌Ǥ\\\\Ȥ߹碌Ǥ' !== ($tmp = mysqli_real_escape_string($link, 'Ȥ߹碌Ǥ\\Ȥ߹碌Ǥ'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('Ȥ߹碌Ǥ\"Ȥ߹碌Ǥ' !== ($tmp = mysqli_real_escape_string($link, 'Ȥ߹碌Ǥ"Ȥ߹碌Ǥ'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("Ȥ߹碌Ǥ\'Ȥ߹碌Ǥ" !== ($tmp = mysqli_real_escape_string($link, "Ȥ߹碌Ǥ'Ȥ߹碌Ǥ"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("Ȥ߹碌Ǥ\\nȤ߹碌Ǥ" !== ($tmp = mysqli_real_escape_string($link, "Ȥ߹碌Ǥ\nȤ߹碌Ǥ"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("Ȥ߹碌Ǥ\\rȤ߹碌Ǥ" !== ($tmp = mysqli_real_escape_string($link, "Ȥ߹碌Ǥ\rȤ߹碌Ǥ"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("Ȥ߹碌Ǥ\\0Ȥ߹碌Ǥ" !== ($tmp = mysqli_real_escape_string($link, "Ȥ߹碌Ǥ" . chr(0) . "Ȥ߹碌Ǥ"))) + printf("[009] Expecting %s, got %s\n", "Ȥ߹碌Ǥ\\0Ȥ߹碌Ǥ", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_euckr.phpt b/ext/mysqli/tests/mysqli_real_escape_string_euckr.phpt new file mode 100644 index 0000000000..a15a51cd80 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_euckr.phpt @@ -0,0 +1,53 @@ +--TEST-- +mysqli_real_escape_string() - euckr +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'euckr')) + die(sprintf("skip Cannot set charset 'euckr'")); +mysqli_close($link); +?> +--FILE-- +<?php + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "euckr")); + + if ('Ǵ뼺\\\\Ǵ뼺' !== ($tmp = mysqli_real_escape_string($link, 'Ǵ뼺\\Ǵ뼺'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('Ǵ뼺\"Ǵ뼺' !== ($tmp = mysqli_real_escape_string($link, 'Ǵ뼺"Ǵ뼺'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("Ǵ뼺\'Ǵ뼺" !== ($tmp = mysqli_real_escape_string($link, "Ǵ뼺'Ǵ뼺"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("Ǵ뼺\\nǴ뼺" !== ($tmp = mysqli_real_escape_string($link, "Ǵ뼺\nǴ뼺"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("Ǵ뼺\\rǴ뼺" !== ($tmp = mysqli_real_escape_string($link, "Ǵ뼺\rǴ뼺"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("Ǵ뼺\\0Ǵ뼺" !== ($tmp = mysqli_real_escape_string($link, "Ǵ뼺" . chr(0) . "Ǵ뼺"))) + printf("[009] Expecting %s, got %s\n", "Ǵ뼺\\0Ǵ뼺", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_gb2312.phpt b/ext/mysqli/tests/mysqli_real_escape_string_gb2312.phpt new file mode 100644 index 0000000000..016115fc68 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_gb2312.phpt @@ -0,0 +1,54 @@ +--TEST-- +mysqli_real_escape_string() - gb2312 +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'gb2312')) + die(sprintf("skip Cannot set charset 'gb2312'")); +mysqli_close($link); +?> +--FILE-- +<?php + + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "gb2312")); + + if ('\\\\' !== ($tmp = mysqli_real_escape_string($link, '\\'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('\"' !== ($tmp = mysqli_real_escape_string($link, '"'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("\'" !== ($tmp = mysqli_real_escape_string($link, "'"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("\\n" !== ($tmp = mysqli_real_escape_string($link, "\n"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("\\r" !== ($tmp = mysqli_real_escape_string($link, "\r"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("\\0" !== ($tmp = mysqli_real_escape_string($link, "" . chr(0) . ""))) + printf("[009] Expecting %s, got %s\n", "\\0", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_gbk.phpt b/ext/mysqli/tests/mysqli_real_escape_string_gbk.phpt new file mode 100644 index 0000000000..bee717f1d3 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_gbk.phpt @@ -0,0 +1,54 @@ +--TEST-- +mysqli_real_escape_string() - gbk +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'gbk')) + die(sprintf("skip Cannot set charset 'gbk'")); +mysqli_close($link); +?> +--FILE-- +<?php + + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "gbk")); + + if ('�İ汾\\\\�İ汾' !== ($tmp = mysqli_real_escape_string($link, '�İ汾\\�İ汾'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('�İ汾\"�İ汾' !== ($tmp = mysqli_real_escape_string($link, '�İ汾"�İ汾'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("�İ汾\'�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾'�İ汾"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("�İ汾\\n�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾\n�İ汾"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("�İ汾\\r�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾\r�İ汾"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("�İ汾\\0�İ汾" !== ($tmp = mysqli_real_escape_string($link, "�İ汾" . chr(0) . "�İ汾"))) + printf("[009] Expecting %s, got %s\n", "�İ汾\\0�İ汾", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "��")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_nobackslash.phpt b/ext/mysqli/tests/mysqli_real_escape_string_nobackslash.phpt new file mode 100644 index 0000000000..bdbcc19c14 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_nobackslash.phpt @@ -0,0 +1,71 @@ +--TEST-- +mysqli_real_escape_string() - SQL Mode NO_BACKSLASH_ESCAPE +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + require_once("connect.inc"); + require_once('table.inc'); + + if (!mysqli_query($link, 'SET @@sql_mode="NO_BACKSLASH_ESCAPES"')) + printf("[001] Cannot set NO_BACKSLASH_ESCAPES, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ('\\' !== ($tmp = mysqli_real_escape_string($link, '\\'))) + printf("[002] Expecting \\, got %s\n", $tmp); + + if ('"' !== ($tmp = mysqli_real_escape_string($link, '"'))) + printf("[003] Expecting \", got %s\n", $tmp); + + if ("''" !== ($tmp = mysqli_real_escape_string($link, "'"))) + printf("[004] Expecting '', got %s\n", $tmp); + + if ("\n" !== ($tmp = mysqli_real_escape_string($link, "\n"))) + printf("[005] Expecting \\n, got %s\n", $tmp); + + if ("\r" !== ($tmp = mysqli_real_escape_string($link, "\r"))) + printf("[006] Expecting \\r, got %s\n", $tmp); + + assert("foo" . chr(0) . "bar" === "foo" . chr(0) . "bar"); + if ("foo" . chr(0) . "bar" !== ($tmp = mysqli_real_escape_string($link, "foo" . chr(0) . "bar"))) + printf("[007] Expecting %s, got %s\n", "foo" . chr(0) . "bar", $tmp); + + if (!mysqli_query($link, sprintf('INSERT INTO test(id, label) VALUES (100, "%s")', + mysqli_real_escape_string($link, "\\")))) + printf("[009] Cannot INSERT, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!($res = mysqli_query($link, 'SELECT label FROM test WHERE id = 100')) || + !($row = mysqli_fetch_assoc($res))) + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + var_dump($row); + mysqli_free_result($res); + + if (!mysqli_query($link, 'SET @@sql_mode=""')) + printf("[011] Cannot disable NO_BACKSLASH_ESCAPES, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if ('\\\\' !== ($tmp = mysqli_real_escape_string($link, '\\'))) + printf("[012] Expecting \\, got %s\n", $tmp); + + if ("foo\\0bar" !== ($tmp = mysqli_real_escape_string($link, "foo" . chr(0) . "bar"))) + printf("[013] Expecting %s, got %s\n", "foo" . chr(0) . "bar", $tmp); + + mysqli_close($link); + + print "done!"; +?> +--EXPECTF-- +array(1) { + ["label"]=> + string(1) "\" +} +done! +--UEXPECTF-- +array(1) { + [u"label"]=> + unicode(1) "\" +} +done! diff --git a/ext/mysqli/tests/mysqli_real_escape_string_sjis.phpt b/ext/mysqli/tests/mysqli_real_escape_string_sjis.phpt new file mode 100644 index 0000000000..7655ecd1e3 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_sjis.phpt @@ -0,0 +1,54 @@ +--TEST-- +mysqli_real_escape_string() - sjis +--SKIPIF-- +<?php +if (ini_get('unicode.semantics')) + die("skip Test cannot be run in unicode mode"); + +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('connect.inc'); + +if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to MySQL, [%d] %s\n", + mysqli_connect_errno(), mysqli_connect_error())); +} +if (!mysqli_set_charset($link, 'sjis')) + die(sprintf("skip Cannot set charset 'sjis'")); +mysqli_close($link); +?> +--FILE-- +<?php + + require_once("connect.inc"); + require_once('table.inc'); + + var_dump(mysqli_set_charset($link, "sjis")); + + if ('?p??\\\\?p??' !== ($tmp = mysqli_real_escape_string($link, '?p??\\?p??'))) + printf("[004] Expecting \\\\, got %s\n", $tmp); + + if ('?p??\"?p??' !== ($tmp = mysqli_real_escape_string($link, '?p??"?p??'))) + printf("[005] Expecting \", got %s\n", $tmp); + + if ("?p??\'?p??" !== ($tmp = mysqli_real_escape_string($link, "?p??'?p??"))) + printf("[006] Expecting ', got %s\n", $tmp); + + if ("?p??\\n?p??" !== ($tmp = mysqli_real_escape_string($link, "?p??\n?p??"))) + printf("[007] Expecting \\n, got %s\n", $tmp); + + if ("?p??\\r?p??" !== ($tmp = mysqli_real_escape_string($link, "?p??\r?p??"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("?p??\\0?p??" !== ($tmp = mysqli_real_escape_string($link, "?p??" . chr(0) . "?p??"))) + printf("[009] Expecting %s, got %s\n", "?p??\\0?p??", $tmp); + + var_dump(mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "?p")')); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +bool(true) +bool(true) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_escape_string_unicode.phpt b/ext/mysqli/tests/mysqli_real_escape_string_unicode.phpt new file mode 100644 index 0000000000..038cca9402 --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_escape_string_unicode.phpt @@ -0,0 +1,84 @@ +--TEST-- +mysqli_real_escape_string() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_real_escape_string())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_real_escape_string($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (NULL !== ($tmp =@mysqli_real_escape_string($link, "фуу", "бар"))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if ('фу\\\\бар' !== ($tmp = mysqli_real_escape_string($link, 'фу\\бар'))) + printf("[004] Expecting фу\\\\бар, got %s\n", $tmp); + + if ('бар\"фус' !== ($tmp = mysqli_real_escape_string($link, 'бар"фус'))) + printf("[005] Expecting бар\"фус, got %s\n", $tmp); + + if ("лала\'лали" !== ($tmp = mysqli_real_escape_string($link, "лала'лали"))) + printf("[006] Expecting лала'лали, got %s\n", $tmp); + + if ("абра\\nкадабра" !== ($tmp = mysqli_real_escape_string($link, "абра\nкадабра"))) + printf("[007] Expecting абра\\nкадабра, got %s\n", $tmp); + + if ("манда\\rин" !== ($tmp = mysqli_real_escape_string($link, "манда\rин"))) + printf("[008] Expecting \\r, got %s\n", $tmp); + + if ("иху\\0аху" !== ($tmp = mysqli_real_escape_string($link, "иху" . chr(0) . "аху"))) + printf("[009] Expecting %s, got %s\n", "иху\\0аху", $tmp); + + if (($exp='абра\\\\ка\"да\\'."'".'бра\Zсим\\nсала\\rби\\0м') !== + ($tmp = mysqli_real_escape_string($link, "абра\\ка\"да'бра\032сим\nсала\rби" . chr(0) . "м"))) + { + printf("[010] Expecting %s, got %s\n", $exp, $tmp, var_dump($exp, $tmp)); + } + + if ('富\\\\酒吧' !== ($tmp = mysqli_real_escape_string($link, '富\\酒吧'))) + printf("[011] Expecting 富\\\\酒吧, got %s\n", $tmp); + + if ('酒吧\"小题大做' !== ($tmp = mysqli_real_escape_string($link, '酒吧"小题大做'))) + printf("[012] Expecting 酒吧\"小题大做, got %s\n", $tmp); + + if ("拉拉\'西雅图" !== ($tmp = mysqli_real_escape_string($link, "拉拉'西雅图"))) + printf("[013] Expecting 拉拉'西雅图, got %s\n", $tmp); + + if ("阿卜拉\\n轻" !== ($tmp = mysqli_real_escape_string($link, "阿卜拉\n轻"))) + printf("[014] Expecting 阿卜拉\\n轻, got %s\n", $tmp); + + if ("张明安\\r在" !== ($tmp = mysqli_real_escape_string($link, "张明安\r在"))) + printf("[015] Expecting 张明安\\r在, got %s\n", $tmp); + + if ("竺可桢\\0空调器" !== ($tmp = mysqli_real_escape_string($link, "竺可桢" . chr(0) . "空调器"))) + printf("[016] Expecting %s, got %s\n", "竺可桢\\0空调器", $tmp); + + if (($exp='阿卜拉\\\\嘉\"达丰\\'."'".'乳罩\Z辛\\n萨拉\\r毕\\0米') !== + ($tmp = mysqli_real_escape_string($link, "阿卜拉\\嘉\"达丰'乳罩\032辛\n萨拉\r毕" . chr(0) . "米"))) + { + printf("[017] Expecting %s, got %s\n", $exp, $tmp, var_dump($exp, $tmp)); + } + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_real_escape_string($link, 'foo'))) + printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_real_escape_string(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_real_query.phpt b/ext/mysqli/tests/mysqli_real_query.phpt new file mode 100644 index 0000000000..e151a9b48d --- /dev/null +++ b/ext/mysqli/tests/mysqli_real_query.phpt @@ -0,0 +1,107 @@ +--TEST-- +mysqli_real_query() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_real_query())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_real_query($link))) + printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + if (NULL !== ($tmp = @mysqli_real_query($link, "SELECT 1 AS a", MYSQLI_USE_RESULT, "foo"))) + printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_real_query($link, 'THIS IS NOT SQL'))) + printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if (false !== ($tmp = mysqli_real_query($link, 'SELECT "this is sql but with backslash g"\g'))) + printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); + + if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link))) + printf("[006] mysqli_errno()/mysqli_error should return some error\n"); + + if (!mysqli_real_query($link, 'SELECT "this is sql but with semicolon" AS valid ; ')) + printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!is_object($res = mysqli_use_result($link))) + printf("[008] Expecting reseult object, got %s/%s [%d] %s\n", gettype($res), $res, mysqli_errno($link), mysqli_error($link)); + + var_dump(mysqli_fetch_assoc($res)); + mysqli_free_result($res); + + if (false !== ($res = mysqli_real_query($link, 'SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES'))) + printf("[008] Expecting boolean/false, got %s/%s, [%d] %s\n", gettype($res), $res, + mysqli_errno($link), mysqli_error($link)); + + if (mysqli_get_server_version($link) > 50000) { + // let's try to play with stored procedures + mysqli_real_query($link, 'DROP PROCEDURE IF EXISTS p'); + if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; +END;')) { + mysqli_real_query($link, 'CALL p(@version)'); + mysqli_real_query($link, 'SELECT @version AS p_version'); + $res = mysqli_store_result($link); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['p_version']) || ('' == $tmp['p_version'])) { + printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + mysqli_real_query($link, 'DROP FUNCTION IF EXISTS f'); + if (mysqli_real_query($link, 'CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN +ver_param;')) { + mysqli_real_query($link, 'SELECT f(VERSION()) AS f_version'); + $res = mysqli_store_result($link); + + $tmp = mysqli_fetch_assoc($res); + if (!is_array($tmp) || empty($tmp) || !isset($tmp['f_version']) || ('' == $tmp['f_version'])) { + printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + var_dump($tmp); + } + + mysqli_free_result($res); + } else { + printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } + } + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_real_query($link, "SELECT id FROM test"))) + printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +array(1) { + ["valid"]=> + string(30) "this is sql but with semicolon" +} + +Warning: mysqli_real_query(): Couldn't fetch mysqli in %s on line %d +done! +--UEXPECTF-- +array(1) { + [u"valid"]=> + unicode(30) "this is sql but with semicolon" +} + +Warning: mysqli_real_query(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_reconnect.phpt b/ext/mysqli/tests/mysqli_reconnect.phpt new file mode 100644 index 0000000000..68cffc3b2b --- /dev/null +++ b/ext/mysqli/tests/mysqli_reconnect.phpt @@ -0,0 +1,130 @@ +--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'); +if (stristr(mysqli_get_client_info(), 'mysqlnd')) + die("skip: test for libmysql"); +?> +--INI-- +mysqli.reconnect=1 +--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 (true !== mysqli_ping($link)) + printf("[010] Reconnect should have happened"); + + if (!$res = mysqli_query($link, "SELECT DATABASE() as _dbname")) + printf("[011] Cannot get database name, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[012] Cannot get database name, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + if ($row['_dbname'] != $db) + printf("[013] Connection should has been made to DB/Schema '%s', expecting '%s', [%d] %s\n", + $row['_dbname'], $db, mysqli_errno($link), mysqli_error($link)); + + // ... and now we try KILL + $thread_id_timeout = mysqli_thread_id($link); + + if (!mysqli_query($link2, sprintf('KILL %d', $thread_id_timeout))) + printf("[014] 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("[015] 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("[016] Processlist is borked, [%d] %s\n", + mysqli_errno($link2), mysqli_error($link)); + + if (true !== ($tmp = mysqli_ping($link))) + printf("[017] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = mysqli_query($link, "SELECT DATABASE() as _dbname")) + printf("[018] Cannot get database name, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[019] Cannot get database name, [%d] %s\n", + mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + if ($row['_dbname'] != $db) + printf("[020] Connection should has been made to DB/Schema '%s', expecting '%s', [%d] %s\n", + $row['_dbname'], $db, mysqli_errno($link), mysqli_error($link)); + + mysqli_close($link); + mysqli_close($link2); + print "done!"; +?> +--EXPECTF-- +done! diff --git a/ext/mysqli/tests/mysqli_report.phpt b/ext/mysqli/tests/mysqli_report.phpt new file mode 100644 index 0000000000..25e1050b6a --- /dev/null +++ b/ext/mysqli/tests/mysqli_report.phpt @@ -0,0 +1,301 @@ +--TEST-- +mysqli_report() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_report())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(-1))) + printf("[002] Expecting boolean/true even for invalid flags, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ERROR))) + printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_STRICT))) + printf("[004] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_INDEX))) + printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ALL))) + printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_OFF))) + printf("[008] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + /* + Internal macro MYSQL_REPORT_ERROR + */ + mysqli_report(MYSQLI_REPORT_ERROR); + + mysqli_multi_query($link, "BAR; FOO;"); + mysqli_query($link, "FOO"); + /* This might work if you accept anonymous users in your setup */ + mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db); + mysqli_kill($link, -1); + + // mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it + mysqli_prepare($link, "FOO"); + mysqli_real_query($link, "FOO"); + if (@mysqli_select_db($link, "Oh lord, let this be an unknown database name")) + printf("[009] select_db should have failed\n"); + // mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it + + + // Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would + // not have been set. If that would be the case, the test would be broken. + mysqli_report(MYSQLI_REPORT_OFF); + + mysqli_multi_query($link, "BAR; FOO;"); + mysqli_query($link, "FOO"); + mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db); + mysqli_kill($link, -1); + mysqli_prepare($link, "FOO"); + mysqli_real_query($link, "FOO"); + mysqli_select_db($link, "Oh lord, let this be an unknown database name"); + + /* + Internal macro MYSQL_REPORT_STMT_ERROR + */ + + mysqli_report(MYSQLI_REPORT_ERROR); + + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "FOO"); + + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + $id = 1; + mysqli_kill($link, mysqli_thread_id($link)); + mysqli_stmt_bind_param($stmt, "i", $id); + mysqli_stmt_close($stmt); + mysqli_close($link); + + /* mysqli_stmt_execute() = mysql_stmt_execute cannot be tested from PHP */ + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[008] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + $id = 1; + mysqli_stmt_bind_param($stmt, "i", $id); + // mysqli_kill($link, mysqli_thread_id($link)); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); + mysqli_close($link); + + /* mysqli_kill() "trick" does not work for any of the following because of an E_COMMANDS_OUT_OF_SYNC */ + /* mysqli_stmt_bind_result() = mysql_stmt_bind_result() cannot be tested from PHP */ + /* mysqli_stmt_fetch() = mysql_stmt_fetch() cannot be tested from PHP */ + /* mysqli_stmt_result_metadata() = mysql_stmt_result_metadata() cannot be tested from PHP */ + /* mysqli_stmt_store_result() = mysql_stmt_store_result() cannot be tested from PHP */ + + // Check + mysqli_report(MYSQLI_REPORT_OFF); + + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[010] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "FOO"); + + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + $id = 1; + mysqli_kill($link, mysqli_thread_id($link)); + mysqli_stmt_bind_param($stmt, "i", $id); + mysqli_stmt_close($stmt); + mysqli_close($link); + + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[011] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + $id = 1; + mysqli_stmt_bind_param($stmt, "i", $id); + mysqli_kill($link, mysqli_thread_id($link)); + mysqli_stmt_execute($stmt); + mysqli_stmt_close($stmt); + mysqli_close($link); + + /* + MYSQLI_REPORT_STRICT + + MYSQLI_REPORT_STRICT ---> + php_mysqli_report_error() -> + MYSQLI_REPORT_MYSQL_ERROR, + MYSQLI_REPORT_STMT_ERROR -> + already tested + + php_mysqli_throw_sql_exception() -> + mysqli_real_connect() + mysqli_connect() + + can't be tested: mysqli_query() via mysql_use_result()/mysql_store_result() + */ + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_report(MYSQLI_REPORT_STRICT); + + try { + + if ($link = mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) + printf("[012] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", + $host, $user . 'unknown_really', $db, $port, $socket); + mysqli_close($link); + + } catch (mysqli_sql_exception $e) { + printf("[013] %s\n", $e->getMessage()); + } + + try { + if (!$link = mysqli_init()) + printf("[014] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + + if ($link = mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) + printf("[015] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", + $host, $user . 'unknown_really', $db, $port, $socket); + mysqli_close($link); + } catch (mysqli_sql_exception $e) { + printf("[016] %s\n", $e->getMessage()); + } + + /* + MYSQLI_REPORT_INDEX ---> + mysqli_query() + mysqli_stmt_execute() + mysqli_prepare() + mysqli_real_query() + mysqli_store_result() + mysqli_use_result() + + No test, because of to many prerequisites: + - Server needs to be started with and + --log-slow-queries --log-queries-not-using-indexes + - query must cause the warning on all MySQL versions + + TODO: + */ + $log_slow_queries = false; + $log_queries_not_using_indexes = false; + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_report(MYSQLI_REPORT_INDEX); + + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[017] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + + // this might cause a warning - no index used + if (!$res = @mysqli_query($link, "SHOW VARIABLES LIKE 'log_slow_queries'")) + printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $log_slow_query = ('ON' == $row['Value']); + + if (mysqli_get_server_version($link) >= 51011) { + // this might cause a warning - no index used + if (!$res = @mysqli_query($link, "SHOW VARIABLES LIKE 'log_queries_not_using_indexes'")) + printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$row = mysqli_fetch_assoc($res)) + printf("[021] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $log_queries_not_using_indexes = ('ON' == $row['Value']); + + if ($log_slow_queries && $log_queries_not_using_indexes) { + + for ($i = 100; $i < 20000; $i++) { + if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES ($i, 'z')")) + printf("[022 - %d] [%d] %s\n", $i - 99, mysqli_errno($link), mysqli_error($link)); + } + + // this might cause a warning - no index used + if (!$res = @mysqli_query($link, "SELECT id, label FROM test WHERE id = 1323")) + printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + } + } + + // Maybe we've provoked an index message, maybe not. + // All we can do is make a few dummy calls to ensure that all codes gets executed which + // checks the flag. Functions to check: mysqli_query() - done above, + // mysqli_stmt_execute(), mysqli_prepare(), mysqli_real_query(), mysqli_store_result() + // mysqli_use_result(), mysqli_thread_safe(), mysqli_thread_id() + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_close($link); + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) + printf("[024] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + + if (!$stmt = mysqli_stmt_init($link)) + printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test')) + printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + if (!mysqli_stmt_execute($stmt)) + printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); + + mysqli_stmt_close($stmt); + + if (!mysqli_real_query($link, 'SELECT label, id FROM test')) + printf("[028] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_use_result($link)) + printf("[029] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + + if (!mysqli_real_query($link, 'SELECT label, id FROM test')) + printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!$res = mysqli_store_result($link)) + printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_free_result($res); + + if (!$stmt = mysqli_prepare($link, 'SELECT id * 3 FROM test')) + printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + else + mysqli_stmt_close($stmt); + + if (!mysqli_query($link, 'INSERT INTO test(id, label) VALUES (100, "z")', MYSQLI_USE_RESULT) || + !mysqli_query($link, 'DELETE FROM test WHERE id > 50', MYSQLI_USE_RESULT)) + printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $tmp = mysqli_thread_safe($link); + $tmp = mysqli_thread_id($link); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_multi_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BAR; FOO' at line 1 in %s on line %d + +Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d + +Warning: mysqli_change_user(): (%d/%d): Access denied for user '0123456789-10-456789-20-456789-%s'@'%s' (using password: YES) in %s on line %d + +Warning: mysqli_kill(): processid should have positive value in %s on line %d + +Warning: mysqli_prepare(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d + +Warning: mysqli_real_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d + +Warning: mysqli_kill(): processid should have positive value in %s on line %d + +Warning: mysqli_stmt_prepare(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d +[013] Access denied for user '%s'@'%s' (using password: YES) +[016] Access denied for user '%s'@'%s' (using password: YES) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_report_wo_ps.phpt b/ext/mysqli/tests/mysqli_report_wo_ps.phpt new file mode 100644 index 0000000000..58aae0af1f --- /dev/null +++ b/ext/mysqli/tests/mysqli_report_wo_ps.phpt @@ -0,0 +1,109 @@ +--TEST-- +mysqli_report() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (NULL !== ($tmp = @mysqli_report())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(-1))) + printf("[002] Expecting boolean/true even for invalid flags, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ERROR))) + printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_STRICT))) + printf("[004] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_INDEX))) + printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ALL))) + printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_OFF))) + printf("[008] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + require('table.inc'); + + /* + Internal macro MYSQL_REPORT_ERROR + */ + mysqli_report(MYSQLI_REPORT_ERROR); + + mysqli_multi_query($link, "BAR; FOO;"); + mysqli_query($link, "FOO"); + mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db); + mysqli_kill($link, -1); + + // mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it + mysqli_real_query($link, "FOO"); + if (@mysqli_select_db($link, "Oh lord, let this be an unknown database name")) + printf("[009] select_db should have failed\n"); + // mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it + + + // Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would + // not have been set. If that would be the case, the test would be broken. + mysqli_report(MYSQLI_REPORT_OFF); + + mysqli_multi_query($link, "BAR; FOO;"); + mysqli_query($link, "FOO"); + mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db); + mysqli_kill($link, -1); + mysqli_real_query($link, "FOO"); + mysqli_select_db($link, "Oh lord, let this be an unknown database name"); + + mysqli_report(MYSQLI_REPORT_OFF); + mysqli_report(MYSQLI_REPORT_STRICT); + + try { + + if ($link = mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) + printf("[010] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", + $host, $user . 'unknown_really', $db, $port, $socket); + mysqli_close($link); + + } catch (mysqli_sql_exception $e) { + printf("[011] %s\n", $e->getMessage()); + } + + try { + if (!$link = mysqli_init()) + printf("[012] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); + + if ($link = mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket)) + printf("[013] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n", + $host, $user . 'unknown_really', $db, $port, $socket); + mysqli_close($link); + } catch (mysqli_sql_exception $e) { + printf("[014] %s\n", $e->getMessage()); + } + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_multi_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BAR; FOO' at line 1 in %s on line %d + +Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d + +Warning: mysqli_change_user(): (%d/%d): Access denied for user '0123456789-10-456789-20-456789-%s'@'%s' (using password: YES) in %s on line %d + +Warning: mysqli_kill(): processid should have positive value in %s on line %d + +Warning: mysqli_real_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOO' at line 1 in %s on line %d + +Warning: mysqli_kill(): processid should have positive value in %s on line %d +[011] Access denied for user '%s'@'%s' (using password: YES) +[014] Access denied for user '%s'@'%s' (using password: YES) +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_result_references.phpt b/ext/mysqli/tests/mysqli_result_references.phpt new file mode 100644 index 0000000000..513d1d07b8 --- /dev/null +++ b/ext/mysqli/tests/mysqli_result_references.phpt @@ -0,0 +1,202 @@ +--TEST-- +References to result sets +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + require_once('connect.inc'); + require_once('table.inc'); + + $references = array(); + + if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) || + !($res = mysqli_store_result($link))) + printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $idx = 0; + while ($row = mysqli_fetch_assoc($res)) { + /* mysqlnd: force seperation - create copies */ + $references[$idx] = array( + 'id' => &$row['id'], + 'label' => $row['label'] . ''); + $references[$idx++]['id'] += 0; + } + + mysqli_close($link); + + mysqli_data_seek($res, 0); + while ($row = mysqli_fetch_assoc($res)) { + /* mysqlnd: force seperation - create copies */ + $references[$idx] = array( + 'id' => &$row['id'], + 'label' => $row['label'] . ''); + $references[$idx++]['id'] += 0; + } + + mysqli_free_result($res); + + 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); + + if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) || + !($res = mysqli_use_result($link))) + printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + while ($row = mysqli_fetch_assoc($res)) { + /* mysqlnd: force seperation - create copies*/ + $references[$idx] = array( + 'id' => &$row['id'], + 'label' => $row['label'] . ''); + $references[$idx]['id2'] = &$references[$idx]['id']; + $references[$idx]['id'] += 1; + $references[$idx++]['id2'] += 1; + } + + $references[$idx++] = &$res; + mysqli_free_result($res); + debug_zval_dump($references); + + if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) || + !($res = mysqli_use_result($link))) + printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $tmp = array(); + while ($row = mysqli_fetch_assoc($res)) { + $tmp[] = $row; + } + $tmp = unserialize(serialize($tmp)); + debug_zval_dump($tmp); + mysqli_free_result($res); + + mysqli_close($link); + print "done!"; +?> +--EXPECTF-- +array(7) refcount(2){ + [0]=> + array(2) refcount(1){ + ["id"]=> + long(1) refcount(1) + ["label"]=> + string(1) "a" refcount(1) + } + [1]=> + array(2) refcount(1){ + ["id"]=> + long(2) refcount(1) + ["label"]=> + string(1) "b" refcount(1) + } + [2]=> + array(2) refcount(1){ + ["id"]=> + long(1) refcount(1) + ["label"]=> + string(1) "a" refcount(1) + } + [3]=> + array(2) refcount(1){ + ["id"]=> + long(2) refcount(1) + ["label"]=> + string(1) "b" refcount(1) + } + [4]=> + array(3) refcount(1){ + ["id"]=> + &long(3) refcount(2) + ["label"]=> + string(1) "a" refcount(1) + ["id2"]=> + &long(3) refcount(2) + } + [5]=> + array(3) refcount(1){ + ["id"]=> + &long(4) refcount(2) + ["label"]=> + string(1) "b" refcount(1) + ["id2"]=> + &long(4) refcount(2) + } + [6]=> + &object(mysqli_result)#2 (0) refcount(2){ + } +} +array(1) refcount(2){ + [0]=> + array(2) refcount(1){ + ["id"]=> + string(1) "1" refcount(1) + ["label"]=> + string(1) "a" refcount(1) + } +} +done! +--UEXPECTF-- +array(7) refcount(2){ + [0]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + long(1) refcount(1) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "a" { 0061 } refcount(1) + } + [1]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + long(2) refcount(1) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "b" { 0062 } refcount(1) + } + [2]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + long(1) refcount(1) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "a" { 0061 } refcount(1) + } + [3]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + long(2) refcount(1) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "b" { 0062 } refcount(1) + } + [4]=> + array(3) refcount(1){ + [u"id" { 0069 0064 }]=> + &long(3) refcount(2) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "a" { 0061 } refcount(1) + [u"id2" { 0069 0064 0032 }]=> + &long(3) refcount(2) + } + [5]=> + array(3) refcount(1){ + [u"id" { 0069 0064 }]=> + &long(4) refcount(2) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "b" { 0062 } refcount(1) + [u"id2" { 0069 0064 0032 }]=> + &long(4) refcount(2) + } + [6]=> + &object(mysqli_result)#2 (0) refcount(2){ + } +} +array(1) refcount(2){ + [0]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + unicode(1) "1" { 0031 } refcount(1) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "a" { 0061 } refcount(1) + } +} +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_result_references_mysqlnd.phpt b/ext/mysqli/tests/mysqli_result_references_mysqlnd.phpt new file mode 100644 index 0000000000..8e2dcf2aca --- /dev/null +++ b/ext/mysqli/tests/mysqli_result_references_mysqlnd.phpt @@ -0,0 +1,139 @@ +--TEST-- +References to result sets - mysqlnd (no copies but references) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); + +require_once('connect.inc'); +if (!$IS_MYSQLND) + die("skip Test for mysqlnd only"); +?> +<?php require_once('skipifemb.inc'); ?> +--FILE-- +<?php + require_once('connect.inc'); + require_once('table.inc'); + + $references = array(); + + if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1")) || + !($res = mysqli_store_result($link))) + printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $idx = 0; + while ($row = mysqli_fetch_assoc($res)) { + /* will overwrite itself */ + $references[$idx]['row_ref'] = &$row; + $references[$idx]['row_copy'] = $row; + $references[$idx]['id_ref'] = &$row['id']; + $references[$idx++]['id_copy'] = $row['id']; + } + mysqli_free_result($res); + + if (!(mysqli_real_query($link, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2")) || + !($res = mysqli_use_result($link))) + printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $rows = array(); + for ($i = 0; $i < 2; $i++) { + $rows[$i] = mysqli_fetch_assoc($res); + $references[$idx]['row_ref'] = &$rows[$i]; + $references[$idx]['row_copy'] = $rows[$i]; + $references[$idx]['id_ref'] = &$rows[$i]['id']; + $references[$idx]['id_copy'] = $rows[$i]['id']; + /* enforce seperation */ + $references[$idx]['id_copy_mod']= $rows[$i]['id'] + 0; + } + mysqli_free_result($res); + + debug_zval_dump($references); + print "done!"; +?> +--EXPECTF-- +array(2) refcount(2){ + [0]=> + array(4) refcount(1){ + ["row_ref"]=> + &NULL refcount(2) + ["row_copy"]=> + array(2) refcount(1){ + ["id"]=> + string(1) "1" refcount(2) + ["label"]=> + string(1) "a" refcount(2) + } + ["id_ref"]=> + string(1) "1" refcount(1) + ["id_copy"]=> + string(1) "1" refcount(1) + } + [1]=> + array(5) refcount(1){ + ["row_ref"]=> + &array(2) refcount(2){ + ["id"]=> + &string(1) "2" refcount(2) + ["label"]=> + string(1) "b" refcount(3) + } + ["row_copy"]=> + array(2) refcount(1){ + ["id"]=> + string(1) "2" refcount(2) + ["label"]=> + string(1) "b" refcount(3) + } + ["id_ref"]=> + &string(1) "2" refcount(2) + ["id_copy"]=> + string(1) "2" refcount(1) + ["id_copy_mod"]=> + long(2) refcount(1) + } +} +done! +--UEXPECTF-- +array(2) refcount(2){ + [0]=> + array(4) refcount(1){ + [u"row_ref" { 0072 006f 0077 005f 0072 0065 0066 }]=> + &NULL refcount(2) + [u"row_copy" { 0072 006f 0077 005f 0063 006f 0070 0079 }]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + unicode(1) "1" { 0031 } refcount(2) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "a" { 0061 } refcount(2) + } + [u"id_ref" { 0069 0064 005f 0072 0065 0066 }]=> + unicode(1) "1" { 0031 } refcount(1) + [u"id_copy" { 0069 0064 005f 0063 006f 0070 0079 }]=> + unicode(1) "1" { 0031 } refcount(1) + } + [1]=> + array(5) refcount(1){ + [u"row_ref" { 0072 006f 0077 005f 0072 0065 0066 }]=> + &array(2) refcount(2){ + [u"id" { 0069 0064 }]=> + &unicode(1) "2" { 0032 } refcount(2) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "b" { 0062 } refcount(3) + } + [u"row_copy" { 0072 006f 0077 005f 0063 006f 0070 0079 }]=> + array(2) refcount(1){ + [u"id" { 0069 0064 }]=> + unicode(1) "2" { 0032 } refcount(2) + [u"label" { 006c 0061 0062 0065 006c }]=> + unicode(1) "b" { 0062 } refcount(3) + } + [u"id_ref" { 0069 0064 005f 0072 0065 0066 }]=> + &unicode(1) "2" { 0032 } refcount(2) + [u"id_copy" { 0069 0064 005f 0063 006f 0070 0079 }]=> + unicode(1) "2" { 0032 } refcount(1) + [u"id_copy_mod" { 0069 0064 005f 0063 006f 0070 0079 005f 006d 006f 0064 }]=> + long(2) refcount(1) + } +} +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_result_unclonable.phpt b/ext/mysqli/tests/mysqli_result_unclonable.phpt new file mode 100644 index 0000000000..93cf663219 --- /dev/null +++ b/ext/mysqli/tests/mysqli_result_unclonable.phpt @@ -0,0 +1,24 @@ +--TEST-- +Trying to clone mysqli_result object +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +?> +--FILE-- +<?php + include "connect.inc"; + + if (!$link = 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); + + if (!($res = mysqli_query($link, "SELECT 'good' AS morning"))) + printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $res_clone = clone $res; + print "done!"; +?> +--EXPECTF-- +Fatal error: Trying to clone an uncloneable object of class mysqli_result in %s on line %d
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_rollback.phpt b/ext/mysqli/tests/mysqli_rollback.phpt new file mode 100644 index 0000000000..fef4cbb321 --- /dev/null +++ b/ext/mysqli/tests/mysqli_rollback.phpt @@ -0,0 +1,85 @@ +--TEST-- +mysqli_rollback() +--SKIPIF-- +<?php ?> +<?php ?> +<?PHP + require_once('skipif.inc'); + require_once('skipifemb.inc'); + require_once('skipifconnectfailure.inc'); + + require_once('connect.inc'); + + if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { + die(sprintf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", + $host, $user, $db, $port, $socket)); + } + + if (!$res = mysqli_query($link, "SHOW VARIABLES LIKE 'have_innodb'")) { + die(sprintf("skip Cannot fetch have_innodb variable\n")); + } + + $row = mysqli_fetch_row($res); + mysqli_free_result($res); + mysqli_close($link); + + if ($row[1] == "DISABLED" || $row[1] == "NO") { + die(sprintf("skip Innodb support is not installed or enabled.")); + } +?> +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if (!is_null($tmp = @mysqli_rollback())) + printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_null($tmp = @mysqli_rollback($link))) + printf("[002] Expecting 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_null($tmp = @mysqli_rollback($link, 'foo'))) + printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (true !== ($tmp = mysqli_autocommit($link, false))) + printf("[005] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp); + + if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) + printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB')) + printf("[007] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)')) + printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $tmp = mysqli_rollback($link); + if ($tmp !== true) + printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + + if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS num FROM test')) + printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $tmp = mysqli_fetch_assoc($res); + if (0 != $tmp['num']) + printf("[12] Expecting 0 rows in table test, found %d rows\n", $tmp['num']); + mysqli_free_result($res); + + if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) + printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + mysqli_close($link); + + if (!is_null($tmp = mysqli_rollback($link))) + printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!\n"; +?> +--EXPECTF-- +Warning: mysqli_rollback(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_rpl_parse_enabled.phpt b/ext/mysqli/tests/mysqli_rpl_parse_enabled.phpt new file mode 100755 index 0000000000..08e612e132 --- /dev/null +++ b/ext/mysqli/tests/mysqli_rpl_parse_enabled.phpt @@ -0,0 +1,46 @@ +--TEST-- +mysqli_rpl_parse_enabled() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +if (!function_exists('mysqli_rpl_parse_enabled')) { + die("skip mysqli_rpl_parse_enabled() 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_rpl_parse_enabled())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_rpl_parse_enabled($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_int($tmp = mysqli_rpl_parse_enabled($link))) + printf("[004] Expecting integer/any value, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_rpl_parse_enabled($link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_rpl_parse_enabled(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_rpl_probe.phpt b/ext/mysqli/tests/mysqli_rpl_probe.phpt new file mode 100755 index 0000000000..778df057e5 --- /dev/null +++ b/ext/mysqli/tests/mysqli_rpl_probe.phpt @@ -0,0 +1,46 @@ +--TEST-- +mysqli_rpl_probe() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +if (!function_exists('mysqli_rpl_probe')) { + die("skip mysqli_rpl_probe() 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_rpl_probe())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_rpl_probe($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_rpl_probe($link))) + printf("[004] Expecting boolean/any value, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_rpl_probe($link))) + printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_rpl_probe(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file diff --git a/ext/mysqli/tests/mysqli_rpl_query_type.phpt b/ext/mysqli/tests/mysqli_rpl_query_type.phpt new file mode 100755 index 0000000000..2fd342f261 --- /dev/null +++ b/ext/mysqli/tests/mysqli_rpl_query_type.phpt @@ -0,0 +1,50 @@ +--TEST-- +mysqli_rpl_query_type() +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifemb.inc'); +require_once('skipifconnectfailure.inc'); +if (!function_exists('mysqli_rpl_query_type')) { + die("skip mysqli_rpl_query_type() 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_rpl_query_type())) + printf("[001] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (NULL !== ($tmp = @mysqli_rpl_query_type($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); + } + + $query = array(); + if (NULL !== ($tmp = @mysqli_rpl_query_type($link, $query))) + printf("[004] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp); + + if (!is_int($tmp = mysqli_rpl_query_type($link, 'SELECT 1'))) + printf("[005] Expecting integer/any value, got %s/%s\n", gettype($tmp), $tmp); + + mysqli_close($link); + + if (NULL !== ($tmp = mysqli_rpl_query_type($link, 'SELECT 1'))) + printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); + + print "done!"; +?> +--EXPECTF-- +Warning: mysqli_rpl_query_type(): Couldn't fetch mysqli in %s on line %d +done!
\ No newline at end of file |