mysqli_character_set_name.phpt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. --TEST--
  2. mysqli_chararcter_set_name(), mysql_client_encoding() [alias]
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. /* NOTE: http://bugs.mysql.com/bug.php?id=7923 makes this test fail very likely on all 4.1.x - 5.0.x! */
  12. require_once("connect.inc");
  13. $tmp = NULL;
  14. $link = NULL;
  15. if (!is_null($tmp = @mysqli_character_set_name()))
  16. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!is_null($tmp = @mysqli_character_set_name($link)))
  18. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  19. if (!is_null($tmp = @mysqli_character_set_name($link, $link, $link)))
  20. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  21. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
  22. printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  23. $host, $user, $db, $port, $socket);
  24. if (!$res = mysqli_query($link, 'SELECT version() AS server_version'))
  25. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  26. $tmp = mysqli_fetch_assoc($res);
  27. mysqli_free_result($res);
  28. $version = explode('.', $tmp['server_version']);
  29. if (empty($version))
  30. printf("[006] Cannot determine server version, need MySQL Server 4.1+ for the test!\n");
  31. if ($version[0] <= 4 && $version[1] < 1)
  32. printf("[007] Need MySQL Server 4.1+ for the test!\n");
  33. if (!$res = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation'))
  34. printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  35. $tmp = mysqli_fetch_assoc($res);
  36. mysqli_free_result($res);
  37. if (!$tmp['charset'])
  38. printf("[009] Cannot determine current character set and collation\n");
  39. $charset = mysqli_character_set_name($link);
  40. if ($tmp['charset'] !== $charset) {
  41. if ($tmp['collation'] === $charset) {
  42. printf("[010] Could be known server bug http://bugs.mysql.com/bug.php?id=7923, collation %s instead of character set returned, expected string/%s, got %s/%s\n",
  43. $tmp['collation'], $tmp['charset'], gettype($charset), $charset);
  44. } else {
  45. printf("[011] Expecting character set %s/%s, got %s/%s\n", gettype($tmp['charset']), $tmp['charset'], gettype($charset), $charset);
  46. }
  47. }
  48. $charset2 = mysqli_character_set_name($link);
  49. if ($charset2 !== $charset) {
  50. printf("[012] Alias mysqli_character_set_name returned %s/%s, expected %s/%s\n", gettype($charset2), $charset2, gettype($charset), $charset);
  51. }
  52. mysqli_close($link);
  53. if (NULL !== ($tmp = @mysqli_character_set_name($link)))
  54. printf("[013] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  55. /* Make sure that the function alias exists */
  56. if (!is_null($tmp = @mysqli_character_set_name()))
  57. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  58. print "done!";
  59. ?>
  60. --EXPECTF--
  61. done!