1--TEST-- 2set character set 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11 require_once 'connect.inc'; 12 13 $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 14 15 if (!mysqli_query($mysql, "SET sql_mode=''")) 16 printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql)); 17 18 $esc_str = chr(0xbf) . chr(0x5c); 19 20 if ($mysql->set_charset("latin1")) { 21 /* 5C should be escaped */ 22 if (3 !== ($tmp = strlen($mysql->real_escape_string($esc_str)))) 23 printf("[003] Expecting 3/int got %s/%s\n", gettype($tmp), $tmp); 24 25 if ('latin1' !== ($tmp = $mysql->character_set_name())) 26 printf("[004] Expecting latin1/string got %s/%s\n", gettype($tmp), $tmp); 27 } 28 29 if ($res = $mysql->query("SHOW CHARACTER SET LIKE 'gbk'")) { 30 $res->free_result(); 31 if ($mysql->set_charset("gbk")) { 32 /* nothing should be escaped, it's a valid gbk character */ 33 34 if (2 !== ($tmp = strlen($mysql->real_escape_string($esc_str)))) 35 printf("[005] Expecting 2/int got %s/%s\n", gettype($tmp), $tmp); 36 37 if ('gbk' !== ($tmp = $mysql->character_set_name())) 38 printf("[005] Expecting gbk/string got %s/%s\n", gettype($tmp), $tmp); 39 } 40 } 41 $mysql->close(); 42 43 print "done!"; 44?> 45--EXPECT-- 46done! 47