mysqli_error.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. mysqli_error()
  3. --EXTENSIONS--
  4. mysqli
  5. --SKIPIF--
  6. <?php
  7. require_once('skipifconnectfailure.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. require_once("connect.inc");
  12. if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
  13. printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  14. $host, $user, $db, $port, $socket);
  15. }
  16. $tmp = mysqli_error($link);
  17. if (!is_string($tmp) || ('' !== $tmp))
  18. printf("[004] Expecting string/empty, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  19. if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) {
  20. printf("[005] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  21. }
  22. mysqli_query($link, 'SELECT * FROM test');
  23. $tmp = mysqli_error($link);
  24. if (!is_string($tmp) || !preg_match("/Table '\w*\.test' doesn't exist/su", $tmp))
  25. printf("[006] Expecting string/[Table... doesn't exit], got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
  26. mysqli_close($link);
  27. try {
  28. mysqli_error($link);
  29. } catch (Error $exception) {
  30. echo $exception->getMessage() . "\n";
  31. }
  32. print "done!";
  33. ?>
  34. --EXPECT--
  35. mysqli object is already closed
  36. done!