1--TEST--
2mysqli_fetch_assoc() - utf8
3--SKIPIF--
4<?php
5	require_once('skipif.inc');
6	require_once('skipifemb.inc');
7	require_once('skipifconnectfailure.inc');
8	require_once("connect.inc");
9
10	if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket))
11		die("skip Cannot connect to server to check charsets");
12
13	if (!$res = mysqli_query($link, "SHOW CHARACTER SET LIKE 'UTF8'"))
14		die("skip Cannot run SHOW CHARACTER SET to check charsets");
15
16	if (!$tmp = mysqli_fetch_assoc($res))
17		die("skip Looks like UTF8 is not available on the server");
18
19	if (strtolower($tmp['Charset']) !== 'utf8')
20		die("skip Not sure if UTF8 is available, canceling the test");
21
22	mysqli_free_result($res);
23
24	if (!$res = mysqli_query($link, "SHOW CHARACTER SET LIKE 'UCS2'"))
25		die("skip Cannot run SHOW CHARACTER SET to check charsets");
26
27	if (!$tmp = mysqli_fetch_assoc($res))
28		die("skip Looks like UCS2 is not available on the server");
29
30	if (strtolower($tmp['Charset']) !== 'ucs2')
31		die("skip Not sure if UCS2 is available, canceling the test");
32
33	mysqli_free_result($res);
34	mysqli_close($link);
35?>
36--FILE--
37<?php
38	require('table.inc');
39
40	/* some cyrillic (utf8) comes here */
41	if (!$res = mysqli_query($link, "SET NAMES UTF8")) {
42		printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43	}
44
45	if (!$res = mysqli_query($link, "SELECT 1 AS 'Андрей Христов', 2 AS 'Улф Вендел', 3 AS 'Георг Рихтер'")) {
46		printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47	}
48	print "[003]\n";
49	var_dump(mysqli_fetch_assoc($res));
50	mysqli_free_result($res);
51
52	if (!$res = mysqli_query($link, "CREATE TABLE автори_на_mysqlnd (id integer not null auto_increment primary key, име varchar(20) character set ucs2, фамилия varchar(20) character set utf8)")) {
53		printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54	}
55	if (!$res = mysqli_query($link, "INSERT INTO автори_на_mysqlnd (име, фамилия) VALUES ('Андрей', 'Христов'), ('Георг', 'Рихтер'), ('Улф','Вендел')")) {
56		printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57	}
58	if (!$res = mysqli_query($link, "INSERT INTO автори_на_mysqlnd (име, фамилия) VALUES ('Andrey', 'Hristov'), ('Georg', 'Richter'), ('Ulf','Wendel')")) {
59		printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
60	}
61	if (!$res = mysqli_query($link, "INSERT INTO автори_на_mysqlnd (име, фамилия) VALUES ('安德烈', 'Hristov'), ('格奥尔', 'Richter'), ('乌尔夫','Wendel')")) {
62		printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63	}
64
65	if (!$res = mysqli_query($link, "SELECT id, име, фамилия FROM автори_на_mysqlnd ORDER BY фамилия, име")) {
66		printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
67	}
68	print "[009]\n";
69	while ($row = mysqli_fetch_assoc($res)) {
70		var_dump($row);
71	}
72	mysqli_free_result($res);
73
74	if (!$res = mysqli_query($link, "DROP TABLE автори_на_mysqlnd")) {
75		printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
76	}
77
78	mysqli_close($link);
79	print "done!";
80?>
81--EXPECTF--
82[003]
83array(3) {
84  ["Андрей Христов"]=>
85  string(%r[1|3]%r) "1"
86  ["Улф Вендел"]=>
87  string(1) "2"
88  ["Георг Рихтер"]=>
89  string(1) "3"
90}
91[009]
92array(3) {
93  ["id"]=>
94  string(1) "4"
95  ["име"]=>
96  string(6) "Andrey"
97  ["фамилия"]=>
98  string(7) "Hristov"
99}
100array(3) {
101  ["id"]=>
102  string(1) "7"
103  ["име"]=>
104  string(9) "安德烈"
105  ["фамилия"]=>
106  string(7) "Hristov"
107}
108array(3) {
109  ["id"]=>
110  string(1) "5"
111  ["име"]=>
112  string(5) "Georg"
113  ["фамилия"]=>
114  string(7) "Richter"
115}
116array(3) {
117  ["id"]=>
118  string(1) "8"
119  ["име"]=>
120  string(9) "格奥尔"
121  ["фамилия"]=>
122  string(7) "Richter"
123}
124array(3) {
125  ["id"]=>
126  string(1) "6"
127  ["име"]=>
128  string(3) "Ulf"
129  ["фамилия"]=>
130  string(6) "Wendel"
131}
132array(3) {
133  ["id"]=>
134  string(1) "9"
135  ["име"]=>
136  string(9) "乌尔夫"
137  ["фамилия"]=>
138  string(6) "Wendel"
139}
140array(3) {
141  ["id"]=>
142  string(1) "3"
143  ["име"]=>
144  string(6) "Улф"
145  ["фамилия"]=>
146  string(12) "Вендел"
147}
148array(3) {
149  ["id"]=>
150  string(1) "2"
151  ["име"]=>
152  string(10) "Георг"
153  ["фамилия"]=>
154  string(12) "Рихтер"
155}
156array(3) {
157  ["id"]=>
158  string(1) "1"
159  ["име"]=>
160  string(12) "Андрей"
161  ["фамилия"]=>
162  string(14) "Христов"
163}
164done!
165