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