1--TEST-- 2mysqli_fetch_assoc() - utf8 3--SKIPIF-- 4<?php 5 require_once('skipif.inc'); 6 require_once('skipifconnectfailure.inc'); 7 require_once("connect.inc"); 8 9 if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 10 die("skip Cannot connect to server to check charsets"); 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--EXPECTF-- 81[003] 82array(3) { 83 ["Андрей Христов"]=> 84 string(%r[1|3]%r) "1" 85 ["Улф Вендел"]=> 86 string(1) "2" 87 ["Георг Рихтер"]=> 88 string(1) "3" 89} 90[009] 91array(3) { 92 ["id"]=> 93 string(1) "4" 94 ["име"]=> 95 string(6) "Andrey" 96 ["фамилия"]=> 97 string(7) "Hristov" 98} 99array(3) { 100 ["id"]=> 101 string(1) "7" 102 ["име"]=> 103 string(9) "安德烈" 104 ["фамилия"]=> 105 string(7) "Hristov" 106} 107array(3) { 108 ["id"]=> 109 string(1) "5" 110 ["име"]=> 111 string(5) "Georg" 112 ["фамилия"]=> 113 string(7) "Richter" 114} 115array(3) { 116 ["id"]=> 117 string(1) "8" 118 ["име"]=> 119 string(9) "格奥尔" 120 ["фамилия"]=> 121 string(7) "Richter" 122} 123array(3) { 124 ["id"]=> 125 string(1) "6" 126 ["име"]=> 127 string(3) "Ulf" 128 ["фамилия"]=> 129 string(6) "Wendel" 130} 131array(3) { 132 ["id"]=> 133 string(1) "9" 134 ["име"]=> 135 string(9) "乌尔夫" 136 ["фамилия"]=> 137 string(6) "Wendel" 138} 139array(3) { 140 ["id"]=> 141 string(1) "3" 142 ["име"]=> 143 string(6) "Улф" 144 ["фамилия"]=> 145 string(12) "Вендел" 146} 147array(3) { 148 ["id"]=> 149 string(1) "2" 150 ["име"]=> 151 string(10) "Георг" 152 ["фамилия"]=> 153 string(12) "Рихтер" 154} 155array(3) { 156 ["id"]=> 157 string(1) "1" 158 ["име"]=> 159 string(12) "Андрей" 160 ["фамилия"]=> 161 string(14) "Христов" 162} 163done! 164