mysql_set_charset.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. mysql_set_charset() - STUB, function usage not recommended
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. if (version_compare(PHP_VERSION, '5.9.9', '>') == 1) {
  8. die('skip set character set not functional with PHP 6 (fomerly PHP 6 && unicode.semantics=On)');
  9. }
  10. if (!function_exists('mysql_set_charset'))
  11. die("skip Function not available");
  12. ?>
  13. --FILE--
  14. <?php
  15. include_once "connect.inc";
  16. $tmp = NULL;
  17. $link = NULL;
  18. if (!is_null($tmp = @mysql_set_charset()))
  19. printf("[001] Expecting NULL got %s/%s\n", $tmp, gettype($tmp));
  20. if (false !== ($tmp = @mysql_set_charset($link)))
  21. printf("[002] Expecting boolean/false got %s/%s\n", $tmp, gettype($tmp));
  22. if (false !== ($tmp = @mysql_set_charset(-1)))
  23. printf("[003] Expecting boolean/false got %s/%s\n", $tmp, gettype($tmp));
  24. if (!is_null($tmp = @mysql_set_charset('somecharset', $link)))
  25. printf("[004] Expecting NULL got %s/%s\n", $tmp, gettype($tmp));
  26. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
  27. printf("[005] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  28. $host, $user, $db, $port, $socket);
  29. /* unicode mode should throw a warning */
  30. $tmp = mysql_set_charset('uFt8', $link);
  31. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1))
  32. $expect = false;
  33. else
  34. $expect = true;
  35. $charsets = array('latin1', 'latin2');
  36. foreach ($charsets as $k => $charset) {
  37. if (!($res = mysql_query(sprintf('SHOW CHARACTER SET LIKE "%s"', $charset), $link)))
  38. continue;
  39. mysql_free_result($res);
  40. if ($expect !== ($tmp = @mysql_set_charset($charset, $link)))
  41. printf("[006] Expecting %s/%s got %s/%s\n",
  42. gettype($expect), $expect,
  43. gettype($tmp), $tmp);
  44. }
  45. mysql_close($link);
  46. print "done!";
  47. ?>
  48. --EXPECTF--
  49. Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
  50. done!