xref: /PHP-8.3/ext/mysqli/tests/mysqli_debug.phpt (revision a21edc52)
1--TEST--
2mysqli_debug()
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?>
18--FILE--
19<?php
20    require_once 'connect.inc';
21
22    // NOTE: documentation is not clear on this: function always return NULL or TRUE
23    if (true !== ($tmp = mysqli_debug(sprintf('d:t:O,%s/mysqli_debug_phpt.trace', sys_get_temp_dir()))))
24        printf("[002] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
25
26    // table.inc will create a database connection and run some SQL queries, therefore
27    // the debug file should have entries
28    require_once 'table.inc';
29
30    clearstatcache();
31    $trace_file = sprintf('%s/mysqli_debug_phpt.trace', sys_get_temp_dir());
32    if (!file_exists($trace_file))
33        printf("[003] Trace file '%s' has not been created\n", $trace_file);
34    if (filesize($trace_file) < 50)
35        printf("[004] Trace file '%s' is very small. filesize() reports only %d bytes. Please check.\n",
36            $trace_file,
37            filesize($trace_file));
38
39    // will mysqli_debug() mind if the trace file gets removed?
40    unlink($trace_file);
41    clearstatcache();
42
43    if (!$res = mysqli_query($link, 'SELECT * FROM test'))
44            printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
45        else
46            mysqli_free_result($res);
47
48    mysqli_close($link);
49
50    clearstatcache();
51    if (!file_exists($trace_file))
52        printf("[006] Trace file '%s' does not exist\n", $trace_file);
53    unlink($trace_file);
54
55    print "done!";
56?>
57--CLEAN--
58<?php
59    require_once 'clean_table.inc';
60?>
61--EXPECTF--
62done%s
63