Annotation of embedaddon/php/ext/mysql/tests/mysql_query.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysql_query()
3: --SKIPIF--
4: <?php
5: require_once('skipif.inc');
6: require_once('skipifconnectfailure.inc');
7: ?>
8: --FILE--
9: <?php
10: include_once("connect.inc");
11:
12: $tmp = NULL;
13: $link = NULL;
14:
15: if (!is_null($tmp = @mysql_query()))
16: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
17:
18: if (false !== ($tmp = @mysql_query($link)))
19: printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
20:
21: require('table.inc');
22:
23: if (NULL !== ($tmp = @mysql_query("SELECT 1 AS a", $link, "foo")))
24: printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
25:
26: if (false !== ($tmp = mysql_query('THIS IS NOT SQL', $link)))
27: printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
28:
29: if (false !== ($tmp = mysql_query("SELECT 'this is sql but with backslash g'\g", $link)))
30: printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
31:
32: if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
33: printf("[006] mysql_errno()/mysql_error should return some error\n");
34:
35: if (!$res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; ", $link))
36: printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
37:
38: var_dump(mysql_fetch_assoc($res));
39: mysql_free_result($res);
40:
41: if (!$res = mysql_query("SELECT 'a' AS ''", $link))
42: printf("[007a] [%d] %s\n", mysql_errno($link), mysql_error($link));
43:
44: var_dump($tmp = mysql_fetch_assoc($res));
45: var_dump($tmp[""]);
46: mysql_free_result($res);
47:
48: if (false !== ($res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES", $link)))
49: printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
50:
51: if (mysql_query('DROP PROCEDURE IF EXISTS p', $link)) {
52: // let's try to play with stored procedures
53: if (mysql_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
54: $res = mysql_query('CALL p(@version)', $link);
55: $res = mysql_query('SELECT @version AS p_version', $link);
56: $tmp = mysql_fetch_assoc($res);
57: if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
58: printf("[009] Result seems wrong, dumping\n");
59: var_dump($tmp);
60: }
61: if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['p_version'])) {
62: printf("[010] Expecting unicode string, dumping\n");
63: var_dump($tmp);
64: }
65: mysql_free_result($res);
66: } else {
67: printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link));
68: }
69:
70: mysql_query('DROP FUNCTION IF EXISTS f', $link);
71: if (mysql_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
72: $res = mysql_query('SELECT f(VERSION()) AS f_version', $link);
73: $tmp = mysql_fetch_assoc($res);
74: if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
75: printf("[012] Result seems wrong, dumping\n");
76: var_dump($tmp);
77: }
78: if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['f_version'])) {
79: printf("[013] Expecting unicode string, dumping\n");
80: var_dump($tmp);
81: }
82: mysql_free_result($res);
83: } else {
84: printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
85: }
86: }
87:
88: mysql_close($link);
89:
90: if (false !== ($tmp = mysql_query("SELECT id FROM test", $link)))
91: printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
92:
93: print "done!";
94: ?>
95: --CLEAN--
96: <?php
97: require_once('connect.inc');
98:
99: // connect + select_db
100: if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
101: printf("[clean] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
102: $host, $myhost, $user, $db, $port, $socket);
103: }
104:
105: if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
106: printf("[clean] Failed to drop test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
107: }
108:
109: /* MySQL server may not support this - ignore errors */
110: @mysql_query('DROP PROCEDURE IF EXISTS p', $link);
111: @mysql_query('DROP FUNCTION IF EXISTS f', $link);
112:
113: mysql_close($link);
114: ?>
115: --EXPECTF--
116: array(1) {
117: [%u|b%"valid"]=>
118: %unicode|string%(30) "this is sql but with semicolon"
119: }
120: array(1) {
121: [%u|b%""]=>
122: %unicode|string%(1) "a"
123: }
124: %unicode|string%(1) "a"
125:
126: Warning: mysql_query(): %d is not a valid MySQL-Link resource in %s on line %d
127: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>