mysqli_debug_append.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --TEST--
  2. mysqli_debug() - append to trace file
  3. --SKIPIF--
  4. <?php
  5. require_once('skipif.inc');
  6. require_once('skipifemb.inc');
  7. require_once('skipifconnectfailure.inc');
  8. if (!function_exists('mysqli_debug'))
  9. die("skip: mysqli_debug() not available");
  10. if (!defined('MYSQLI_DEBUG_TRACE_ENABLED'))
  11. die("skip: can't say for sure if mysqli_debug works");
  12. if (defined('MYSQLI_DEBUG_TRACE_ENABLED') && !MYSQLI_DEBUG_TRACE_ENABLED)
  13. die("skip: debug functionality not enabled");
  14. if (!$IS_MYSQLND)
  15. die("SKIP Libmysql feature not sufficiently spec'd in MySQL C API documentation");
  16. ?>
  17. --FILE--
  18. <?php
  19. require_once('connect.inc');;
  20. if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir()))))
  21. printf("[001] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  22. // table.inc will create a database connection and run some SQL queries, therefore
  23. // the debug file should have entries
  24. require_once('table.inc');
  25. clearstatcache();
  26. $trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir());
  27. if (!file_exists($trace_file))
  28. printf("[002] Trace file '%s' has not been created\n", $trace_file);
  29. if (filesize($trace_file) < 50)
  30. printf("[003] Trace file '%s' is very small. filesize() reports only %d bytes. Please check.\n",
  31. $trace_file,
  32. filesize($trace_file));
  33. // will mysqli_debug() mind if the trace file gets removed?
  34. unlink($trace_file);
  35. clearstatcache();
  36. if (!$fp = fopen($trace_file, 'w')) {
  37. printf("[004] Cannot create trace file to test append mode\n");
  38. } else {
  39. if (!fwrite($fp, (binary) 'mysqli_debug.phpt test line'))
  40. printf("[005] Cannot write to trace file.\n");
  41. fclose($fp);
  42. if (true !== ($tmp = mysqli_debug(sprintf('d:a,%s', $trace_file))))
  43. printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  44. if (!$res = mysqli_query($link, 'SELECT * FROM test'))
  45. printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  46. else
  47. mysqli_free_result($res);
  48. $trace = file_get_contents($trace_file);
  49. if (!strstr($trace, 'mysqli_debug.phpt test line'))
  50. printf("[008] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check.");
  51. if (true !== ($tmp = mysqli_debug(sprintf('d:A,%s', $trace_file))))
  52. printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
  53. if (!$res = mysqli_query($link, 'SELECT * FROM test'))
  54. printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
  55. else
  56. mysqli_free_result($res);
  57. if (!strstr(file_get_contents($trace_file), $trace))
  58. printf("[011] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check.");
  59. }
  60. // what will happen if we create new trace entries...?
  61. unlink($trace_file);
  62. clearstatcache();
  63. if (file_exists($trace_file))
  64. printf("[012] Could not remove trace file '%s'.\n", $trace_file);
  65. mysqli_close($link);
  66. print "done";
  67. if ($IS_MYSQLND)
  68. print "libmysql/DBUG package prints some debug info here."
  69. ?>
  70. --CLEAN--
  71. <?php
  72. require_once("clean_table.inc");
  73. ?>
  74. --EXPECTF--
  75. done%s