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