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  [%u|b%"Андрей Христов"]=>
85  %unicode|string%(%r[1|3]%r) "1"
86  [%u|b%"Улф Вендел"]=>
87  %unicode|string%(1) "2"
88  [%u|b%"Георг Рихтер"]=>
89  %unicode|string%(1) "3"
90}
91[009]
92array(3) {
93  [%u|b%"id"]=>
94  %unicode|string%(1) "4"
95  [%u|b%"име"]=>
96  %unicode|string%(6) "Andrey"
97  [%u|b%"фамилия"]=>
98  %unicode|string%(7) "Hristov"
99}
100array(3) {
101  [%u|b%"id"]=>
102  %unicode|string%(1) "7"
103  [%u|b%"име"]=>
104  %unicode|string%(9) "安德烈"
105  [%u|b%"фамилия"]=>
106  %unicode|string%(7) "Hristov"
107}
108array(3) {
109  [%u|b%"id"]=>
110  %unicode|string%(1) "5"
111  [%u|b%"име"]=>
112  %unicode|string%(5) "Georg"
113  [%u|b%"фамилия"]=>
114  %unicode|string%(7) "Richter"
115}
116array(3) {
117  [%u|b%"id"]=>
118  %unicode|string%(1) "8"
119  [%u|b%"име"]=>
120  %unicode|string%(9) "格奥尔"
121  [%u|b%"фамилия"]=>
122  %unicode|string%(7) "Richter"
123}
124array(3) {
125  [%u|b%"id"]=>
126  %unicode|string%(1) "6"
127  [%u|b%"име"]=>
128  %unicode|string%(3) "Ulf"
129  [%u|b%"фамилия"]=>
130  %unicode|string%(6) "Wendel"
131}
132array(3) {
133  [%u|b%"id"]=>
134  %unicode|string%(1) "9"
135  [%u|b%"име"]=>
136  %unicode|string%(9) "乌尔夫"
137  [%u|b%"фамилия"]=>
138  %unicode|string%(6) "Wendel"
139}
140array(3) {
141  [%u|b%"id"]=>
142  %unicode|string%(1) "3"
143  [%u|b%"име"]=>
144  %unicode|string%(6) "Улф"
145  [%u|b%"фамилия"]=>
146  %unicode|string%(12) "Вендел"
147}
148array(3) {
149  [%u|b%"id"]=>
150  %unicode|string%(1) "2"
151  [%u|b%"име"]=>
152  %unicode|string%(10) "Георг"
153  [%u|b%"фамилия"]=>
154  %unicode|string%(12) "Рихтер"
155}
156array(3) {
157  [%u|b%"id"]=>
158  %unicode|string%(1) "1"
159  [%u|b%"име"]=>
160  %unicode|string%(12) "Андрей"
161  [%u|b%"фамилия"]=>
162  %unicode|string%(14) "Христов"
163}
164done!