mysqli_info.phpt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --TEST--
  2. mysqli_info()
  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. require_once("connect.inc");
  12. if (!is_null($tmp = @mysqli_info()))
  13. printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  14. if (!is_null($tmp = @mysqli_info(NULL)))
  15. printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  16. require "table.inc";
  17. if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, 'a')"))
  18. printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  19. // NOTE: empty string, no multiple insert syntax
  20. if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp))
  21. printf("[004] Expecting null, got %s/%s\n", gettype($tmp), $tmp);
  22. if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (101, 'a'), (102, 'b')"))
  23. printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  24. if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
  25. printf("[006] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
  26. if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp))
  27. printf("[007] Expecting unicode, because unicode mode it on. Got binary string\n");
  28. if (!$res = mysqli_query($link, 'INSERT INTO test(id, label) SELECT id + 200, label FROM test'))
  29. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  30. if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
  31. printf("[008] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
  32. if (!$res = mysqli_query($link, 'ALTER TABLE test MODIFY label CHAR(2)'))
  33. printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  34. if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
  35. printf("[010] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
  36. if (!$res = mysqli_query($link, "UPDATE test SET label = 'b' WHERE id >= 100"))
  37. printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  38. if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
  39. printf("[012] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
  40. if (!$res = mysqli_query($link, "SELECT 1"))
  41. printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  42. if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp))
  43. printf("[014] Expecting null, got %s/%s\n", gettype($tmp), $tmp);
  44. mysqli_free_result($res);
  45. // NOTE: no LOAD DATA INFILE test
  46. if ($dir = sys_get_temp_dir()) {
  47. do {
  48. $file = $dir . '/' . 'mysqli_info_phpt.cvs';
  49. if (!$fp = fopen($file, 'w'))
  50. /* ignore this error */
  51. break;
  52. if (!fwrite($fp, b"100;'a';\n") ||
  53. !fwrite($fp, b"101;'b';\n") ||
  54. !fwrite($fp, b"102;'c';\n")) {
  55. @unlink($file);
  56. break;
  57. }
  58. fclose($fp);
  59. if (!mysqli_query($link, "DELETE FROM test")) {
  60. printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  61. break;
  62. }
  63. if (!@mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY '\n'", $file))) {
  64. /* ok, because we might not be allowed to do this */
  65. @unlink($file);
  66. break;
  67. }
  68. if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
  69. printf("[016] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
  70. unlink($file);
  71. } while (false);
  72. }
  73. print "done!";
  74. ?>
  75. --CLEAN--
  76. <?php
  77. require_once("clean_table.inc");
  78. ?>
  79. --EXPECTF--
  80. done!