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