065.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. --TEST--
  2. set character set
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (!function_exists('mysqli_set_charset')) {
  8. die('skip mysqli_set_charset() not available');
  9. }
  10. if (version_compare(PHP_VERSION, '5.9.9', '>') == 1) {
  11. die('skip set character set not functional with PHP 6 (fomerly PHP 6 && unicode.semantics=On)');
  12. }
  13. ?>
  14. --FILE--
  15. <?php
  16. require_once("connect.inc");
  17. if (!$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
  18. printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
  19. if (!mysqli_query($mysql, "SET sql_mode=''"))
  20. printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));
  21. $esc_str = chr(0xbf) . chr(0x5c);
  22. $len = $charset = array();
  23. $tmp = null;
  24. if ($mysql->set_charset("latin1")) {
  25. /* 5C should be escaped */
  26. if (3 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
  27. printf("[003] Expecting 3/int got %s/%s\n", gettype($tmp), $tmp);
  28. if ('latin1' !== ($tmp = $mysql->character_set_name()))
  29. printf("[004] Expecting latin1/string got %s/%s\n", gettype($tmp), $tmp);
  30. }
  31. if ($res = $mysql->query("SHOW CHARACTER SET LIKE 'gbk'")) {
  32. $res->free_result();
  33. if ($mysql->set_charset("gbk")) {
  34. /* nothing should be escaped, it's a valid gbk character */
  35. if (2 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
  36. printf("[005] Expecting 2/int got %s/%s\n", gettype($tmp), $tmp);
  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. print "done!";
  43. ?>
  44. --EXPECT--
  45. done!