summaryrefslogtreecommitdiff
path: root/ext/mysql
diff options
context:
space:
mode:
authorUlf Wendel <uw@php.net>2007-10-10 09:56:48 +0000
committerUlf Wendel <uw@php.net>2007-10-10 09:56:48 +0000
commitdb9cdc1b66d21588e0e47db725260ca41b97b9a8 (patch)
tree9d432851a63ee0c5901e4b4652da379f5a92da09 /ext/mysql
parent865d199df3468eeff17db619f1498cef8ca9941a (diff)
downloadphp-git-db9cdc1b66d21588e0e47db725260ca41b97b9a8.tar.gz
And the last set of new tests for ext/mysql. "new" does not really mean new.
We've checked them into HEAD/PHP6 before already.
Diffstat (limited to 'ext/mysql')
-rw-r--r--ext/mysql/tests/mysql_list_dbs.phpt50
-rw-r--r--ext/mysql/tests/mysql_list_fields.phpt33
-rw-r--r--ext/mysql/tests/mysql_list_processes.phpt52
-rw-r--r--ext/mysql/tests/mysql_list_tables.phpt81
-rw-r--r--ext/mysql/tests/mysql_query.phpt120
-rw-r--r--ext/mysql/tests/mysql_query_load_data_openbasedir.phpt108
-rw-r--r--ext/mysql/tests/mysql_real_escape_string.phpt52
-rw-r--r--ext/mysql/tests/mysql_result.phpt158
-rw-r--r--ext/mysql/tests/mysql_select_db.phpt79
-rw-r--r--ext/mysql/tests/mysql_set_charset.phpt59
-rw-r--r--ext/mysql/tests/mysql_sql_safe_mode.phpt39
-rw-r--r--ext/mysql/tests/mysql_stat.phpt48
-rw-r--r--ext/mysql/tests/mysql_tablename.phpt65
-rw-r--r--ext/mysql/tests/mysql_thread_id.phpt39
-rw-r--r--ext/mysql/tests/mysql_trace_mode.phpt33
-rw-r--r--ext/mysql/tests/mysql_unbuffered_query.phpt114
16 files changed, 1130 insertions, 0 deletions
diff --git a/ext/mysql/tests/mysql_list_dbs.phpt b/ext/mysql/tests/mysql_list_dbs.phpt
new file mode 100644
index 0000000000..f79ee2d127
--- /dev/null
+++ b/ext/mysql/tests/mysql_list_dbs.phpt
@@ -0,0 +1,50 @@
+--TEST--
+mysql_list_dbs()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (false !== ($tmp = @mysql_list_dbs(NULL)))
+ printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if (NULL !== ($tmp = @mysql_list_dbs($link, $link)))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (!$res = mysql_list_dbs($link))
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!$num = mysql_num_rows($res))
+ printf("[004] Empty database list? [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+$row = mysql_fetch_array($res, MYSQL_NUM);
+if (ini_get('unicode.semantics') && !is_unicode($row[0])) {
+ printf("[005] Check for unicode support\n");
+ var_inspect($row);
+}
+
+mysql_free_result($res);
+
+if (!$res2 = mysql_list_dbs())
+ printf("[006] [%d] %s\n", mysql_errno(), mysql_error());
+
+$row2 = mysql_fetch_array($res2, MYSQL_NUM);
+mysql_free_result($res2);
+
+assert($row === $row2);
+
+mysql_close($link);
+
+print "done!\n";
+?>
+--EXPECTF--
+done!
diff --git a/ext/mysql/tests/mysql_list_fields.phpt b/ext/mysql/tests/mysql_list_fields.phpt
new file mode 100644
index 0000000000..87b3cf6b89
--- /dev/null
+++ b/ext/mysql/tests/mysql_list_fields.phpt
@@ -0,0 +1,33 @@
+--TEST--
+mysql_list_fields()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+// This will implicitly try to connect, and we don't want it
+//if (false !== ($tmp = mysql_list_fields($link, $link)))
+// printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (!$res = mysql_list_fields($db, 'test', $link))
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!($num = mysql_num_fields($res)))
+ printf("[004] Empty field list? [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+mysql_free_result($res);
+mysql_close($link);
+
+print "done!";
+?>
+--EXPECTF--
+done!
diff --git a/ext/mysql/tests/mysql_list_processes.phpt b/ext/mysql/tests/mysql_list_processes.phpt
new file mode 100644
index 0000000000..9cf51db617
--- /dev/null
+++ b/ext/mysql/tests/mysql_list_processes.phpt
@@ -0,0 +1,52 @@
+--TEST--
+mysql_list_processes()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (NULL !== ($tmp = @mysql_list_processes($link, $link)))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (!$res = mysql_list_processes($link))
+ printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!$num = mysql_num_rows($res))
+ printf("[003] Empty process list? [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+$row = mysql_fetch_array($res, MYSQL_NUM);
+if (ini_get('unicode.semantics') && !is_unicode($row[0])) {
+ printf("[004] Check for unicode support\n");
+ var_inspect($row);
+}
+
+mysql_free_result($res);
+
+if (!$res = mysql_list_processes())
+ printf("[005] [%d] %s\n", mysql_errno(), mysql_error());
+
+if (!$num = mysql_num_rows($res))
+ printf("[006] Empty process list? [%d] %s\n", mysql_errno(), mysql_error());
+
+$row = mysql_fetch_array($res, MYSQL_NUM);
+if (ini_get('unicode.semantics') && !is_unicode($row[0])) {
+ printf("[007] Check for unicode support\n");
+ var_inspect($row);
+}
+
+mysql_free_result($res);
+mysql_close($link);
+
+print "done!\n";
+?>
+--EXPECTF--
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_list_tables.phpt b/ext/mysql/tests/mysql_list_tables.phpt
new file mode 100644
index 0000000000..6b66dd7067
--- /dev/null
+++ b/ext/mysql/tests/mysql_list_tables.phpt
@@ -0,0 +1,81 @@
+--TEST--
+mysql_list_tables()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (NULL !== ($tmp = @mysql_list_tables()))
+ printf("[001] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
+
+if (NULL !== ($tmp = @mysql_list_tables('too', 'many', 'arguments')))
+ printf("[002] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = @mysql_list_tables(NULL)))
+ printf("[003] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = @mysql_list_tables($db, NULL)))
+ printf("[004] Expecting boolean/false got %s/%s\n", gettype($tmp), $tmp);
+
+require_once('table.inc');
+
+if (!$res_def = @mysql_list_tables($db))
+ printf("[005] [%d] %s\n", mysql_errno(), mysql_error());
+
+if (!$res = @mysql_list_tables($db, $link))
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!$res_query = mysql_query("SHOW TABLES", $link))
+ printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+$tables_def = $tables = $tables_query = array();
+
+while ($row = mysql_fetch_assoc($res_def))
+ $tables_def[] = $row;
+mysql_free_result($res_def);
+
+while ($row = mysql_fetch_assoc($res))
+ $tables[] = $row;
+mysql_free_result($res);
+
+while ($row = mysql_fetch_assoc($res_query))
+ $tables_query[] = $row;
+mysql_free_result($res_query);
+
+if ($tables_def !== $tables) {
+ printf("[008] Got different table lists for default link and specified link\n");
+ var_dump($tables_def);
+ var_dump($tables);
+}
+
+$list1 = $list2 = array();
+foreach ($tables as $k => $tlist)
+ foreach ($tlist as $k => $table)
+ $list1[] = $table;
+
+foreach ($tables_query as $k => $tlist)
+ foreach ($tlist as $k => $table)
+ $list2[] = $table;
+
+if ($list1 !== $list2) {
+ printf("[009] Got different results for mysql_list_tables() and SHOW TABLES\n");
+ var_dump($list1);
+ var_dump($list2);
+}
+
+if (!in_array('test', $list1))
+ printf("[010] Table lists seem to be wrong. Check manually.\n");
+
+mysql_close($link);
+
+print "done!\n";
+?>
+--EXPECTF--
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_query.phpt b/ext/mysql/tests/mysql_query.phpt
new file mode 100644
index 0000000000..d1d4dfb8e9
--- /dev/null
+++ b/ext/mysql/tests/mysql_query.phpt
@@ -0,0 +1,120 @@
+--TEST--
+mysql_query()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once("connect.inc");
+
+$tmp = NULL;
+$link = NULL;
+
+if (!is_null($tmp = @mysql_query()))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = @mysql_query($link)))
+ printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (NULL !== ($tmp = @mysql_query("SELECT 1 AS a", $link, "foo")))
+ printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_query('THIS IS NOT SQL', $link)))
+ printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_query('SELECT "this is sql but with backslash g"\g', $link)))
+ printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
+ printf("[006] mysql_errno()/mysql_error should return some error\n");
+
+if (!$res = mysql_query('SELECT "this is sql but with semicolon" AS valid ; ', $link))
+ printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+var_dump(mysql_fetch_assoc($res));
+mysql_free_result($res);
+
+if (!$res = mysql_query('SELECT "a" AS ""', $link))
+ printf("[007a] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+var_dump($tmp = mysql_fetch_assoc($res));
+var_dump($tmp[""]);
+mysql_free_result($res);
+
+if (false !== ($res = mysql_query('SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES', $link)))
+ printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (mysql_query('DROP PROCEDURE IF EXISTS p', $link)) {
+ // let's try to play with stored procedures
+ if (mysql_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
+ $res = mysql_query('CALL p(@version)', $link);
+ $res = mysql_query('SELECT @version AS p_version', $link);
+ $tmp = mysql_fetch_assoc($res);
+ if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
+ printf("[009] Result seems wrong, dumping\n");
+ var_dump($tmp);
+ }
+ if (ini_get('unicode.semantics') && !is_unicode($tmp['p_version'])) {
+ printf("[010] Expecting unicode string, dumping\n");
+ var_dump($tmp);
+ }
+ mysql_free_result($res);
+ } else {
+ printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link));
+ }
+
+ mysql_query('DROP FUNCTION IF EXISTS f', $link);
+ if (mysql_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
+ $res = mysql_query('SELECT f(VERSION()) AS f_version', $link);
+ $tmp = mysql_fetch_assoc($res);
+ if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
+ printf("[012] Result seems wrong, dumping\n");
+ var_dump($tmp);
+ }
+ if (ini_get('unicode.semantics') && !is_unicode($tmp['f_version'])) {
+ printf("[013] Expecting unicode string, dumping\n");
+ var_dump($tmp);
+ }
+ mysql_free_result($res);
+ } else {
+ printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
+ }
+}
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_query("SELECT id FROM test", $link)))
+ printf("[011] Expecting boolean/false, 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: mysql_query(): %d is not a valid MySQL-Link resource 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: mysql_query(): %d is not a valid MySQL-Link resource in %s on line %d
+done!
diff --git a/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt
new file mode 100644
index 0000000000..d007080431
--- /dev/null
+++ b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt
@@ -0,0 +1,108 @@
+--TEST--
+LOAD DATA INFILE - open_basedir
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+
+if (file_exists('./simple.csv') && !unlink('./simple.csv'))
+ die("skip Cannot remove previous CSV file");
+
+if (!$fp = fopen('./simple.csv', 'w'))
+ die("skip Cannot create test CSV file");
+
+flose($fp);
+@unlink('./simple.csv');
+?>
+--INI--
+safe_mode=0
+open_basedir="."
+--FILE--
+<?php
+@include_once("connect.inc");
+if (!isset($db)) {
+ // run-tests, I love you for not allowing me to set ini settings dynamically
+ print "[006] [1148] The used command is not allowed with this MySQL version
+[007] [0]
+[008] LOAD DATA not run?
+[010] [1148] The used command is not allowed with this MySQL version
+done!";
+ die();
+}
+require('table.inc');
+mysql_close($link);
+if ($socket)
+ $host = sprintf("%s:%s", $host, $socket);
+else if ($port)
+ $host = sprintf("%s:%s", $host, $port);
+
+if (!$link = mysql_connect($host, $user, $passwd, true, 128)) {
+ printf("[001] Cannot connect using host '%s', user '%s', password '****', [%d] %s\n",
+ $host, $user, $passwd,
+ mysql_errno(), mysql_error());
+}
+
+if (!mysql_select_db($db, $link)) {
+ printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
+}
+
+if (file_exists('./simple.csv'))
+ unlink('./simple.csv');
+
+if (!$fp = fopen('./simple.csv', 'w'))
+ printf("[003] Cannot open CSV file\n");
+
+if (ini_get('unicode.semantics')) {
+ if (!fwrite($fp, (binary)"'97';'x';\n") ||
+ !fwrite($fp, (binary)"'98';'y';\n") ||
+ !fwrite($fp, (binary)"99;'z';\n")) {
+ printf("[004] Cannot write CVS file '%s'\n", $file);
+ }
+} else {
+ if (!fwrite($fp, "97;'x';\n") ||
+ !fwrite($fp, "98;'y';\n") ||
+ !fwrite($fp, "99;'z';\n")) {
+ printf("[005] Cannot write CVS file '%s'\n", $file);
+ }
+}
+fclose($fp);
+
+$sql = sprintf("LOAD DATA LOCAL INFILE '%s'
+ INTO TABLE test
+ FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
+ LINES TERMINATED BY '\n'",
+ mysql_real_escape_string(realpath('./simple.csv'), $link));
+
+if (!mysql_query($sql, $link))
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!($res = mysql_query('SELECT label FROM test WHERE id = 97', $link)) ||
+ !($row = mysql_fetch_assoc($res)) ||
+ !mysql_free_result($res))
+ printf("[007] [%d] '%s'\n", mysql_errno($link), mysql_error($link));
+
+if ($row['label'] != "x")
+ printf("[008] LOAD DATA not run?\n");
+
+if (!mysql_query('DELETE FROM test', $link))
+ printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+$sql = "LOAD DATA LOCAL INFILE '/tmp/idonotexist'
+ INTO TABLE test
+ FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\''
+ LINES TERMINATED BY '\n'";
+
+if (!mysql_query($sql, $link))
+ printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+mysql_close($link);
+unlink("./simple.csv");
+
+print "done!";
+?>
+--EXPECTF--
+[006] [1148] %s
+[007] [0] ''
+[008] LOAD DATA not run?
+[010] [1148] %s
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_real_escape_string.phpt b/ext/mysql/tests/mysql_real_escape_string.phpt
new file mode 100644
index 0000000000..511da068bd
--- /dev/null
+++ b/ext/mysql/tests/mysql_real_escape_string.phpt
@@ -0,0 +1,52 @@
+--TEST--
+mysql_real_escape_string()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (NULL !== ($tmp = @mysql_real_escape_string()))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (NULL !== ($tmp = @mysql_real_escape_string('foo', $link, $link)))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+var_dump(mysql_real_escape_string("Am I a unicode string in PHP 6?", $link));
+var_dump(mysql_real_escape_string('\\', $link));
+var_dump(mysql_real_escape_string('"', $link));
+var_dump(mysql_real_escape_string("'", $link));
+var_dump(mysql_real_escape_string("\n", $link));
+var_dump(mysql_real_escape_string("\r", $link));
+var_dump($tmp = mysql_real_escape_string("foo" . chr(0) . "bar", $link));
+
+assert($tmp === mysql_real_escape_string("foo" . chr(0) . "bar"));
+
+print "done!";
+?>
+--EXPECTF--
+string(31) "Am I a unicode string in PHP 6?"
+string(2) "\\"
+string(2) "\""
+string(2) "\'"
+string(2) "\n"
+string(2) "\r"
+string(8) "foo\0bar"
+done!
+--UEXPECTF--
+unicode(31) "Am I a unicode string in PHP 6?"
+unicode(2) "\\"
+unicode(2) "\""
+unicode(2) "\'"
+unicode(2) "\n"
+unicode(2) "\r"
+unicode(8) "foo\0bar"
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_result.phpt b/ext/mysql/tests/mysql_result.phpt
new file mode 100644
index 0000000000..4217b2e390
--- /dev/null
+++ b/ext/mysql/tests/mysql_result.phpt
@@ -0,0 +1,158 @@
+--TEST--
+mysql_result()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+require_once("connect.inc");
+
+$tmp = NULL;
+$link = NULL;
+
+// string mysql_result ( resource result, int row [, mixed field] )
+
+if (!is_null($tmp = @mysql_result()))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (!is_null($tmp = @mysql_result($link)))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require_once('table.inc');
+if (!$res = mysql_query("SELECT id, label, id AS _id, CONCAT(label, 'a') _label, NULL as _foo FROM test _test ORDER BY id ASC LIMIT 1", $link)) {
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
+}
+
+var_dump(mysql_result($res, -1));
+var_dump(mysql_result($res, 2));
+
+var_dump(mysql_result($res, 0, -1));
+var_dump(mysql_result($res, 0, 500));
+
+print "valid fields\n";
+var_dump(mysql_result($res, 0));
+var_dump(mysql_result($res, 0, 1));
+
+var_dump(mysql_result($res, 0, 'id'));
+var_dump(mysql_result($res, 0, '_test.id'));
+var_dump(mysql_result($res, 0, 'label'));
+var_dump(mysql_result($res, 0, '_test.label'));
+print "some invalid fields\n";
+var_dump(mysql_result($res, 0, 'unknown'));
+var_dump(mysql_result($res, 0, '_test.'));
+var_dump(mysql_result($res, 0, chr(0)));
+var_dump(mysql_result($res, 0, '_test.' . chr(0)));
+print "_id\n";
+var_dump(mysql_result($res, 0, '_id'));
+print "_label\n";
+var_dump(mysql_result($res, 0, '_label'));
+print "_foo\n";
+var_dump(mysql_result($res, 0, '_foo'));
+var_dump(mysql_result($res, 0, 'test.id'));
+var_dump(mysql_result($res, 0, 'test.label'));
+
+mysql_free_result($res);
+
+var_dump(mysql_result($res, 0));
+
+mysql_close($link);
+print "done!";
+?>
+--EXPECTF--
+Warning: mysql_result(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Unable to jump to row 2 on MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Bad column offset specified in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Bad column offset specified in %s on line %d
+bool(false)
+valid fields
+string(1) "1"
+string(1) "a"
+string(1) "1"
+string(1) "1"
+string(1) "a"
+string(1) "a"
+some invalid fields
+
+Warning: mysql_result(): unknown not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): _test. not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): _test. not found in MySQL result index %d in %s on line %d
+bool(false)
+_id
+string(1) "1"
+_label
+string(2) "aa"
+_foo
+NULL
+
+Warning: mysql_result(): test.id not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): test.label not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): %d is not a valid MySQL result resource in %s on line %d
+bool(false)
+done!
+--UEXPECTF--
+Warning: mysql_result(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Unable to jump to row 2 on MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Bad column offset specified in %s on line %d
+bool(false)
+
+Warning: mysql_result(): Bad column offset specified in %s on line %d
+bool(false)
+valid fields
+unicode(1) "1"
+unicode(1) "a"
+unicode(1) "1"
+unicode(1) "1"
+unicode(1) "a"
+unicode(1) "a"
+some invalid fields
+
+Warning: mysql_result(): unknown not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): _test. not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): _test. not found in MySQL result index %d in %s on line %d
+bool(false)
+_id
+unicode(1) "1"
+_label
+string(2) "aa"
+_foo
+NULL
+
+Warning: mysql_result(): test.id not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): test.label not found in MySQL result index %d in %s on line %d
+bool(false)
+
+Warning: mysql_result(): %d is not a valid MySQL result resource in %s on line %d
+bool(false)
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_select_db.phpt b/ext/mysql/tests/mysql_select_db.phpt
new file mode 100644
index 0000000000..3391fa6e95
--- /dev/null
+++ b/ext/mysql/tests/mysql_select_db.phpt
@@ -0,0 +1,79 @@
+--TEST--
+mysql_select_db()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (false !== ($tmp = @mysql_select_db($link)))
+ printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if (!$link = my_mysql_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 (!is_null($tmp = @mysql_select_db($db, $link, "foo")))
+ printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+/* does not make too much sense, unless we have access to at least one more database than $db */
+if (!mysql_select_db($db, $link))
+ printf("[004] Cannot select DB %s, [%d] %s\n", $db, mysql_errno($link), mysql_error($link));
+
+if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
+ printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (!$row = mysql_fetch_assoc($res))
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if ($row['dbname'] !== (string)$db)
+ printf("[007] Expecting database '%s', found '%s'\n", $db, $row['dbname']);
+
+var_dump($row['dbname']);
+
+mysql_free_result($res);
+
+if (mysql_select_db('mysql', $link)) {
+ // Yippie, a second database to play with - that's great because mysql_select_db
+ // ($db) was done by mysql__connect() already and the previous test
+ // was quite useless
+ if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
+ printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+ if (!$row = mysql_fetch_assoc($res))
+ printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+ if (strtolower($row['dbname']) !== 'mysql')
+ printf("[010] Expecting database 'mysql', found '%s'\n", $row['dbname']);
+
+ mysql_free_result($res);
+}
+
+
+var_dump(mysql_select_db('I can not imagine that this database exists', $link));
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_select_db($db, $link)))
+ printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+print "done!\n";
+?>
+--EXPECTF--
+string(%d) "%s"
+bool(false)
+
+Warning: mysql_select_db(): %d is not a valid MySQL-Link resource in %s on line %d
+done!
+--UEXPECTF--
+unicode(%d) "%s"
+bool(false)
+
+Warning: mysql_select_db(): %d is not a valid MySQL-Link resource in %s on line %d
+done!
diff --git a/ext/mysql/tests/mysql_set_charset.phpt b/ext/mysql/tests/mysql_set_charset.phpt
new file mode 100644
index 0000000000..0fbff44e88
--- /dev/null
+++ b/ext/mysql/tests/mysql_set_charset.phpt
@@ -0,0 +1,59 @@
+--TEST--
+mysql_set_charset() - STUB, function usage not recommended
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+if (!function_exists('mysql_set_charset'))
+ die("skip Function not available");
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (!is_null($tmp = @mysql_set_charset()))
+ printf("[001] Expecting NULL got %s/%s\n", $tmp, gettype($tmp));
+
+if (false !== ($tmp = @mysql_set_charset($link)))
+ printf("[002] Expecting boolean/false got %s/%s\n", $tmp, gettype($tmp));
+
+if (false !== ($tmp = @mysql_set_charset(-1)))
+ printf("[003] Expecting boolean/false got %s/%s\n", $tmp, gettype($tmp));
+
+if (!is_null($tmp = @mysql_set_charset('somecharset', $link)))
+ printf("[004] Expecting NULL got %s/%s\n", $tmp, gettype($tmp));
+
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
+ printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
+ $host, $user, $db, $port, $socket);
+
+/* unicode mode should throw a warning */
+$tmp = mysql_set_charset('uFt8', $link);
+
+if (ini_get('unicode.semantics'))
+ $expect = false;
+else
+ $expect = true;
+
+$charsets = array('latin1', 'latin2');
+foreach ($charsets as $k => $charset) {
+ if (!($res = mysql_query(sprintf('SHOW CHARACTER SET LIKE "%s"', $charset), $link)))
+ continue;
+ mysql_free_result($res);
+ if ($expect !== ($tmp = @mysql_set_charset($charset, $link)))
+ printf("[006] Expecting %s/%s got %s/%s\n",
+ gettype($expect), $expect,
+ gettype($tmp), $tmp);
+}
+
+mysql_close($link);
+print "done!";
+?>
+--EXPECTF--
+done!
+--UEXPECTF--
+Warning: mysql_set_charset(): Character set %s is not supported when running PHP with unicode.semantics=On. in %s on line %d
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_sql_safe_mode.phpt b/ext/mysql/tests/mysql_sql_safe_mode.phpt
new file mode 100644
index 0000000000..6c652fb579
--- /dev/null
+++ b/ext/mysql/tests/mysql_sql_safe_mode.phpt
@@ -0,0 +1,39 @@
+--TEST--
+mysql_[p]connect() - safe_mode
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+$link = @mysql_connect("", "", "", true);
+if ($link)
+ die("skip Test cannot be run if annonymous connections are allowed");
+?>
+--INI--
+sql.safe_mode=1
+--FILE--
+<?php
+require_once('connect.inc');
+if ($socket)
+ $host = sprintf("%s:%s", $host, $socket);
+else if ($port)
+ $host = sprintf("%s:%s", $host, $port);
+
+if ($link = mysql_connect($host, $user, $passwd, true)) {
+ printf("[001] Safe mode not working properly?\n");
+ mysql_close($link);
+}
+
+if ($link = mysql_pconnect($host, $user, $passwd)) {
+ printf("[002] Safe mode not working properly?\n");
+ mysql_close($link);
+}
+print "done!\n";
+?>
+--EXPECTF--
+Notice: mysql_connect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d
+
+Warning: mysql_connect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d
+
+Notice: mysql_pconnect(): SQL safe mode in effect - ignoring host/user/password information in %s on line %d
+
+Warning: mysql_pconnect(): Access denied for user '%s'@'%s' (using password: NO) in %s on line %d
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_stat.phpt b/ext/mysql/tests/mysql_stat.phpt
new file mode 100644
index 0000000000..bc5be9540d
--- /dev/null
+++ b/ext/mysql/tests/mysql_stat.phpt
@@ -0,0 +1,48 @@
+--TEST--
+mysql_stat()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$dbname = 'test';
+$tmp = NULL;
+$link = NULL;
+
+if (!is_null($tmp = @mysql_stat($link)))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (!is_null($tmp = @mysql_stat($link, "foo")))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if ((!is_string($stat = mysql_stat($link))) || ('' === $stat))
+ printf("[003] Expecting non empty string, got %s/'%s', [%d] %s\n",
+ gettype($stat), $stat, mysql_errno($link), mysql_error($link));
+
+if (ini_get('unicode.semantics') && !is_unicode($stat)) {
+ printf("[004] Expecting Unicode error message!\n");
+ var_inspect($stat);
+}
+
+if ((!is_string($stat_def = mysql_stat())) || ('' === $stat_def))
+ printf("[003] Expecting non empty string, got %s/'%s', [%d] %s\n",
+ gettype($stat_def), $stat_def, mysql_errno(), mysql_error());
+
+assert($stat === $stat_def);
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_stat($link)))
+ printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+print "done!";
+?>
+--EXPECTF--
+Warning: mysql_stat(): %d is not a valid MySQL-Link resource in %s on line %d
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_tablename.phpt b/ext/mysql/tests/mysql_tablename.phpt
new file mode 100644
index 0000000000..7524cdb343
--- /dev/null
+++ b/ext/mysql/tests/mysql_tablename.phpt
@@ -0,0 +1,65 @@
+--TEST--
+mysql_tablename()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (!is_null($tmp = @mysql_tablename()))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (null !== ($tmp = @mysql_tablename($link)))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+if (!$res = mysql_query("SELECT id, label FROM test ORDER BY id LIMIT 2", $link)) {
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
+}
+
+if (NULL !== ($tmp = mysql_tablename($res)))
+ printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_tablename($res, -1)))
+ printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+var_dump(mysql_tablename($res, 0));
+
+if (false !== ($tmp = mysql_tablename($res, 2)))
+ printf("[00%d] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+mysql_free_result($res);
+
+var_dump(mysql_tablename($res, 0));
+
+mysql_close($link);
+print "done!";
+?>
+--EXPECTF--
+Warning: Wrong parameter count for mysql_tablename() in %s on line %d
+
+Warning: mysql_tablename(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
+string(1) "1"
+
+Warning: mysql_tablename(): Unable to jump to row 2 on MySQL result index %d in %s on line %d
+
+Warning: mysql_tablename(): %d is not a valid MySQL result resource in %s on line %d
+bool(false)
+done!
+--UEXPECTF--
+Warning: Wrong parameter count for mysql_tablename() in %s on line %d
+
+Warning: mysql_tablename(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
+unicode(1) "1"
+
+Warning: mysql_tablename(): Unable to jump to row 2 on MySQL result index %d in %s on line %d
+
+Warning: mysql_tablename(): %d is not a valid MySQL result resource in %s on line %d
+bool(false)
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_thread_id.phpt b/ext/mysql/tests/mysql_thread_id.phpt
new file mode 100644
index 0000000000..b05bb3ed1c
--- /dev/null
+++ b/ext/mysql/tests/mysql_thread_id.phpt
@@ -0,0 +1,39 @@
+--TEST--
+mysql_thread_id()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once "connect.inc";
+
+$tmp = NULL;
+$link = NULL;
+
+if (!is_null($tmp = @mysql_thread_id($link)))
+ printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (!is_int($id = mysql_thread_id($link)) || (0 === $id))
+ printf("[002] Expecting int/any but zero, got %s/%s. [%d] %s\n",
+ gettype($id), $id, mysql_errno($link), mysql_error($link));
+
+if (!is_int($id_def = mysql_thread_id()) || (0 === $id_def))
+ printf("[003] Expecting int/any but zero, got %s/%s. [%d] %s\n",
+ gettype($id_def), $id_def, mysql_errno(), mysql_error());
+
+assert($id === $id_def);
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_thread_id($link)))
+ printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+print "done!";
+?>
+--EXPECTF--
+Warning: mysql_thread_id(): %d is not a valid MySQL-Link resource in %s on line %d
+done! \ No newline at end of file
diff --git a/ext/mysql/tests/mysql_trace_mode.phpt b/ext/mysql/tests/mysql_trace_mode.phpt
new file mode 100644
index 0000000000..86fa5e081b
--- /dev/null
+++ b/ext/mysql/tests/mysql_trace_mode.phpt
@@ -0,0 +1,33 @@
+--TEST--
+mysql.trace_mode=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--INI--
+mysql.trace_mode=1
+error_reporting=E_ALL | E_NOTICE | E_STRICT
+--FILE--
+<?php
+require_once('connect.inc');
+require_once('table.inc');
+
+$res1 = mysql_query('SELECT id FROM test', $link);
+
+if (!$res2 = mysql_db_query('phptest', 'SELECT id FROM test', $link))
+ printf("[001] [%d] %s\n", mysql_errno($link), mysql_error($link));
+mysql_free_result($res2);
+print mysql_escape_string("I don't mind character sets, do I?\n");
+
+$res3 = mysql_query('BOGUS_SQL', $link);
+mysql_close($link);
+
+print "done!\n";
+?>
+--EXPECTF--
+Notice: mysql_db_query(): This function is deprecated; use mysql_query() instead%sin %s on line %d
+
+Warning: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in %s on line %d
+I don\'t mind character sets, do I?\n
+Warning: mysql_query(): 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 'BOGUS_SQL' at line 1 in %s on line %d
+done!
+
+Warning: Unknown: 1 result set(s) not freed. Use mysql_free_result to free result sets which were requested using mysql_query() in %s on line %d
diff --git a/ext/mysql/tests/mysql_unbuffered_query.phpt b/ext/mysql/tests/mysql_unbuffered_query.phpt
new file mode 100644
index 0000000000..6701ce52a0
--- /dev/null
+++ b/ext/mysql/tests/mysql_unbuffered_query.phpt
@@ -0,0 +1,114 @@
+--TEST--
+mysql_unbuffered_query()
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once('skipifconnectfailure.inc');
+?>
+--FILE--
+<?php
+include_once("connect.inc");
+
+$tmp = NULL;
+$link = NULL;
+
+if (false !== ($tmp = @mysql_unbuffered_query($link)))
+ printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+require('table.inc');
+
+if (NULL !== ($tmp = @mysql_unbuffered_query("SELECT 1 AS a", $link, "foo")))
+ printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_unbuffered_query('THIS IS NOT SQL', $link)))
+ printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if (false !== ($tmp = mysql_unbuffered_query('SELECT "this is sql but with backslash g"\g', $link)))
+ printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
+ printf("[005] mysql_errno()/mysql_error should return some error\n");
+
+if (!$res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; ', $link))
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+var_dump(mysql_fetch_assoc($res));
+mysql_free_result($res);
+
+if (false !== ($res = mysql_unbuffered_query('SELECT "this is sql but with semicolon" AS valid ; SHOW VARIABLES', $link)))
+ printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
+
+if (mysql_unbuffered_query('DROP PROCEDURE IF EXISTS p', $link)) {
+ // let's try to play with stored procedures
+ if (mysql_unbuffered_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
+ $res = mysql_unbuffered_query('CALL p(@version)', $link);
+ $res = mysql_unbuffered_query('SELECT @version AS p_version', $link);
+ $tmp = mysql_fetch_assoc($res);
+ if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
+ printf("[008] Result seems wrong, dumping\n");
+ var_dump($tmp);
+ }
+ if (ini_get('unicode.semantics') && !is_unicode($tmp['p_version'])) {
+ printf("[009] Expecting unicode string, dumping\n");
+ var_dump($tmp);
+ }
+ mysql_free_result($res);
+ } else {
+ printf("[010] [%d] %s\n", mysql_errno($link), mysql_error($link));
+ }
+
+ mysql_unbuffered_query('DROP FUNCTION IF EXISTS f', $link);
+ if (mysql_unbuffered_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
+ $res = mysql_unbuffered_query('SELECT f(VERSION()) AS f_version', $link);
+ $tmp = mysql_fetch_assoc($res);
+ if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
+ printf("[011] Result seems wrong, dumping\n");
+ var_dump($tmp);
+ }
+ if (ini_get('unicode.semantics') && !is_unicode($tmp['f_version'])) {
+ printf("[012] Expecting unicode string, dumping\n");
+ var_dump($tmp);
+ }
+ mysql_free_result($res);
+ } else {
+ printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
+ }
+}
+
+var_dump(mysql_unbuffered_query('INSERT INTO test(id) VALUES (100)', $link));
+var_dump($res = mysql_unbuffered_query('SELECT id FROM test', $link));
+var_dump(mysql_num_rows($res));
+
+mysql_close($link);
+
+if (false !== ($tmp = mysql_unbuffered_query("SELECT id FROM test", $link)))
+ printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
+
+print "done!";
+?>
+--EXPECTF--
+array(1) {
+ ["valid"]=>
+ string(30) "this is sql but with semicolon"
+}
+bool(true)
+resource(%d) of type (mysql result)
+int(0)
+
+Notice: mysql_close(): Function called without first fetching all rows from a previous unbuffered query in %s on line %d
+
+Warning: mysql_unbuffered_query(): %d is not a valid MySQL-Link resource in %s on line %d
+done!
+--UEXPECTF--
+array(1) {
+ [u"valid"]=>
+ unicode(30) "this is sql but with semicolon"
+}
+bool(true)
+resource(%d) of type (mysql result)
+int(0)
+
+Notice: mysql_close(): Function called without first fetching all rows from a previous unbuffered query in %s on line %d
+
+Warning: mysql_unbuffered_query(): %d is not a valid MySQL-Link resource in %s on line %d
+done!