mysqli_debug_append.phpt 3.4 KB

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