1--TEST--
2mysqli_query() - unicode (cyrillic)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9require_once('table.inc');
10if (!$res = mysqli_query($link, "SHOW CHARACTER SET LIKE 'utf8'"))
11	die("skip UTF8 chatset seems not available");
12mysqli_free_result($res);
13mysqli_close($link);
14?>
15--FILE--
16<?php
17	include_once("connect.inc");
18
19	$tmp    = NULL;
20	$link   = NULL;
21
22	if (!is_null($tmp = @mysqli_query()))
23		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
24
25	if (!is_null($tmp = @mysqli_query($link)))
26		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
27
28	require_once('table.inc');
29
30	if (TRUE !== ($tmp = @mysqli_query($link, "set names utf8")))
31		printf("[002.5] Expecting TRUE, got %s/%s\n", gettype($tmp), $tmp);
32
33	if (NULL !== ($tmp = @mysqli_query($link, "SELECT 1 AS колона", MYSQLI_USE_RESULT, "foo")))
34		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
35
36	if (false !== ($tmp = mysqli_query($link, 'това не е ескюел')))
37		printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
38
39	if (false !== ($tmp = mysqli_query($link, "SELECT 'това е ескюел, но със обратна наклонена и g'\g")))
40		printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
41
42	if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link)))
43		printf("[006] mysqli_errno()/mysqli_error should return some error\n");
44
45	if (!$res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; "))
46		printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47
48	var_dump(mysqli_fetch_assoc($res));
49	mysqli_free_result($res);
50
51	if (false !== ($res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; SHOW VARIABLES")))
52		printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53
54	if (mysqli_get_server_version($link) > 50000) {
55		// let's try to play with stored procedures
56		mysqli_query($link, 'DROP PROCEDURE IF EXISTS процедурка');
57		if (mysqli_query($link, 'CREATE PROCEDURE процедурка(OUT версия VARCHAR(25)) BEGIN SELECT VERSION() INTO версия; END;')) {
58			$res = mysqli_query($link, 'CALL процедурка(@version)');
59			$res = mysqli_query($link, 'SELECT @version AS п_версия');
60
61			$tmp = mysqli_fetch_assoc($res);
62			if (!is_array($tmp) || empty($tmp) || !isset($tmp['п_версия']) || ('' == $tmp['п_версия'])) {
63				printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
64				var_dump($tmp);
65			}
66
67			mysqli_free_result($res);
68		} else {
69			printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
70		}
71
72		mysqli_query($link, 'DROP FUNCTION IF EXISTS функцийка');
73		if (mysqli_query($link, 'CREATE FUNCTION функцийка( параметър_версия VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN параметър_версия;')) {
74			$res = mysqli_query($link, 'SELECT функцийка(VERSION()) AS ф_версия');
75
76			$tmp = mysqli_fetch_assoc($res);
77			if (!is_array($tmp) || empty($tmp) || !isset($tmp['ф_версия']) || ('' == $tmp['ф_версия'])) {
78				printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
79				var_dump($tmp);
80			}
81
82			mysqli_free_result($res);
83		} else {
84			printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
85		}
86	}
87
88	/*
89	Trying to test what Ramil suggests in http://bugs.mysql.com/bug.php?id=29576
90	However, this won't work, because we're lacking MYSQLI_SET_CHARSET_NAME.
91	if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1)) {
92		if (mysqli_get_server_version() > 50002) {
93			@mysqli_query($link, "DROP USER IF EXISTS 'тест'@'%'");
94			if (TRUE !== mysqli_query($link, "CREATE USER 'тест'@'%'")) {
95				var_dump(mysqli_error($link);
96			}
97		}
98		if (TRUE !== mysqli_query($link, "GRANT SELECT ON $db.* TO 'тест'@'%' IDENTIFIED BY 'парола'")) {
99			var_dump(mysqli_error($link);
100		} else {
101			$link2 = mysqli_init();
102			if (!(mysqli_real_connect($link2, $host, "тест", 'парола', $db, $port, $socket))) {
103				printf("[011] Cannot connect to the server using host=%s, user=%s, passwd=парола, dbname=%s, port=%s, socket=%s, [%d] %s\n",
104					$host, "тест", $db, $port, $socket,
105					mysqli_connect_errno(), mysqli_connect_error());
106			}
107			mysqli_close($link2);
108			if (mysqli_get_server_version() > 50002) {
109				if (!mysqli_query($link, "DROP USER 'тест'@'%'"))
110					printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
111				} else {
112					printf("[015] Cannot create user or grant privileges, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
113				}
114			}
115		}
116	}
117	*/
118
119	mysqli_close($link);
120
121	if (NULL !== ($tmp = mysqli_query($link, "SELECT id FROM test")))
122		printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
123
124	print "done!";
125?>
126--EXPECTF--
127array(1) {
128  [%u|b%"правилен"]=>
129  %unicode|string%(%d) "това ескюел, но с точка и запетая"
130}
131
132Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d
133done!