mysql_errno.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. mysql_errno()
  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_errno()))
  14. printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  15. if (null !== ($tmp = @mysql_errno($link)))
  16. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  17. if (!is_null($tmp = @mysql_errno($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. var_dump(mysql_errno($link));
  24. if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
  25. printf("[004] Failed to drop old test table: [%d] %s\n", mysql_errno($link), mysql_errno($link));
  26. }
  27. mysql_query('SELECT * FROM test', $link);
  28. var_dump(mysql_errno($link));
  29. mysql_close($link);
  30. var_dump(mysql_errno($link));
  31. if ($link = @mysql_connect($host . '_unknown', $user . '_unknown', $passwd, true)) {
  32. printf("[005] Can connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  33. $host . '_unknown', $user . '_unknown', $db, $port, $socket);
  34. } else {
  35. $errno = mysql_errno();
  36. if (!is_int($errno))
  37. printf("[006] Expecting int/any (e.g 1046, 2005) got %s/%s\n", gettype($errno), $errno);
  38. }
  39. print "done!";
  40. ?>
  41. --CLEAN--
  42. <?php
  43. require_once("clean_table.inc");
  44. ?>
  45. --EXPECTF--
  46. 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
  47. int(0)
  48. int(%d)
  49. Warning: mysql_errno(): %d is not a valid MySQL-Link resource in %s on line %d
  50. bool(false)
  51. done!