function try_control_string($link, $control_string, $trace_file, $offset) { if (true !== ($tmp = mysqli_debug($control_string))) { printf("[%03d][control string '%s'] Expecting boolean/true, got %s/%s.\n", $offset + 1, $control_string, gettype($tmp), $tmp); return false; } if (!($res = mysqli_query($link, 'SELECT * FROM test'))) { printf("[%03d][control string '%s'] [%d] %s.\n", $offset + 2, $control_string, mysqli_errno($link), mysqli_error($link)); return false; } clearstatcache(); if (!file_exists($trace_file)) { printf("[%03d][control string '%s'] Trace file has not been written.\n", $offset + 3, $control_string, gettype($tmp), $tmp); return false; } unlink($trace_file); }
function try_control_string($link, $control_string, $trace_file, $offset) { @unlink($trace_file); if (true !== ($tmp = @mysqli_debug($control_string))) { printf("[%03d][control string '%s'] Expecting boolean/true, got %s/%s.\n", $offset + 1, $control_string, gettype($tmp), $tmp); return false; } if (!($res = mysqli_query($link, 'SELECT * FROM test'))) { printf("[%03d][control string '%s'] [%d] %s.\n", $offset + 2, $control_string, mysqli_errno($link), mysqli_error($link)); return false; } while ($row = mysqli_fetch_assoc($res)) { } mysqli_free_result($res); clearstatcache(); if (!file_exists($trace_file)) { printf("[%03d][control string '%s'] Trace file has not been written.\n", $offset + 3, $control_string, gettype($tmp), $tmp); return false; } return trim(substr(file_get_contents($trace_file), 0, 100024)); }
<?php require_once 'connect.inc'; // NOTE: documentation is not clear on this: function always return NULL or TRUE if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir())))) { printf("[002] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } if ($IS_MYSQLND) { // let's make this mysqlnd only - for libmysql we need debug installation // table.inc will create a database connection and run some SQL queries, therefore // the debug file should have entries $test_table_name = 'test_mysqli_debug_table_1'; require_once 'table.inc'; clearstatcache(); $trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir()); if (!file_exists($trace_file)) { printf("[003] Trace file '%s' has not been created\n", $trace_file); } if (filesize($trace_file) < 50) { printf("[004] Trace file '%s' is very small. filesize() reports only %d bytes. Please check.\n", $trace_file, filesize($trace_file)); } // will mysqli_debug() mind if the trace file gets removed? unlink($trace_file); clearstatcache(); if (!($res = mysqli_query($link, 'SELECT * FROM test'))) { printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } else { mysqli_free_result($res); } mysqli_close($link); clearstatcache();
printf("[005] Cannot write to trace file.\n"); } fclose($fp); if (true !== ($tmp = mysqli_debug(sprintf('d:a,%s', $trace_file)))) { printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = mysqli_query($link, 'SELECT * FROM test'))) { printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } else { mysqli_free_result($res); } $trace = file_get_contents($trace_file); if (!strstr($trace, 'mysqli_debug.phpt test line')) { printf("[008] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check."); } if (true !== ($tmp = mysqli_debug(sprintf('d:A,%s', $trace_file)))) { printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); } if (!($res = mysqli_query($link, 'SELECT * FROM test'))) { printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } else { mysqli_free_result($res); } if (!strstr(file_get_contents($trace_file), $trace)) { printf("[011] Cannot find original file content any more. Seems that the trace file got overwritten and not appended. Please check."); } } // what will happen if we create new trace entries...? unlink($trace_file); clearstatcache(); if (file_exists($trace_file)) {