mysql_error.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. mysql_error()
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifconnectfailure.inc');
  7. ?>
  8. --FILE--
  9. <?php
  10. include "connect.inc";
  11. $tmp = NULL;
  12. $link = NULL;
  13. if (false !== ($tmp = @mysql_error()))
  14. printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  15. if (NULL !== ($tmp = @mysql_error($link)))
  16. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!is_null($tmp = @mysql_error($link, 'too many args')))
  18. printf("[002b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  19. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
  20. printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  21. $host, $user, $db, $port, $socket);
  22. }
  23. $tmp = mysql_error($link);
  24. if (!is_string($tmp) || ('' !== $tmp))
  25. printf("[004] Expecting string/empty, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
  26. if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
  27. printf("[005] Failed to drop old test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
  28. }
  29. mysql_query('SELECT * FROM test', $link);
  30. $tmp = mysql_error($link);
  31. if (!is_string($tmp) || !preg_match("/Table '\w*\.test' doesn't exist/su", $tmp))
  32. printf("[006] Expecting string/[Table... doesn't exit], got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
  33. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp)) {
  34. printf("[007] Expecting Unicode error message!\n");
  35. var_inspect($tmp);
  36. }
  37. mysql_close($link);
  38. var_dump(mysql_error($link));
  39. if ($link = @mysql_connect($host . '_unknown', $user . '_unknown', $passwd, true)) {
  40. printf("[008] Can connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  41. $host . '_unknown', $user . '_unknown', $db, $port, $socket);
  42. }
  43. if ('' == mysql_error())
  44. printf("[009] Connect error should have been set\n");
  45. print "done!";
  46. ?>
  47. --CLEAN--
  48. <?php
  49. require_once("clean_table.inc");
  50. ?>
  51. --EXPECTF--
  52. 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
  53. Warning: mysql_error(): %d is not a valid MySQL-Link resource in %s on line %d
  54. bool(false)
  55. done!