1--TEST--
2mysqli_debug() - invalid debug control strings
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    require_once 'table.inc';
22
23    function try_control_string($link, $control_string, $trace_file, $offset) {
24
25        if (true !== ($tmp = mysqli_debug($control_string))) {
26            printf("[%03d][control string '%s'] Expecting boolean/true, got %s/%s.\n",
27                $offset + 1,
28                $control_string,
29                gettype($tmp),
30                $tmp);
31            return false;
32        }
33
34        if (!$res = mysqli_query($link, 'SELECT * FROM test')) {
35            printf("[%03d][control string '%s'] [%d] %s.\n",
36                $offset + 2,
37                $control_string,
38                mysqli_errno($link),
39                mysqli_error($link));
40            return false;
41        }
42
43        clearstatcache();
44        if (!file_exists($trace_file)) {
45            printf("[%03d][control string '%s'] Trace file has not been written.\n",
46                $offset + 3,
47                $control_string,
48                gettype($tmp),
49                $tmp);
50            return false;
51        }
52
53        unlink($trace_file);
54    }
55
56    $trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'mysqli_debug_phpt.trace');
57    try_control_string($link, 't:,,:o,' . $trace_file, $trace_file, 10);
58    try_control_string($link, ':' . chr(0) . 'A,' . $trace_file, $trace_file, 20);
59    try_control_string($link, 't:o,' . $trace_file . ':abc', $trace_file, 30);
60    try_control_string($link, 't:o,' . $trace_file . ':ABC,123:b', $trace_file, 40);
61    try_control_string($link, 't:ABC,123:b;:o,' . $trace_file, $trace_file, 50);
62    try_control_string($link, 't:A;BC,123:b;:o,' . $trace_file, $trace_file, 60);
63    try_control_string($link, 't:p:o,' . $trace_file, $trace_file, 70);
64    try_control_string($link, 't:p,1,,2:o,' . $trace_file, $trace_file, 80);
65    try_control_string($link, 't:z,1,,2:o,' . $trace_file, $trace_file, 90);#
66
67    mysqli_close($link);
68    print "done";
69    print "libmysql/DBUG package prints some debug info here."
70?>
71--EXPECTF--
72Warning: mysqli_debug(): Unrecognized format ',' in %s on line %d
73
74Warning: mysqli_debug(): Consecutive semicolons at position 0 in %s on line %d
75[023][control string '%s'] Trace file has not been written.
76
77Warning: mysqli_debug(): Colon expected, 'b' found in %s on line %d
78
79Warning: mysqli_debug(): Colon expected, 'c' found in %s on line %d
80
81Warning: mysqli_debug(): Colon expected, 'B' found in %s on line %d
82
83Warning: mysqli_debug(): Colon expected, 'C' found in %s on line %d
84
85Warning: mysqli_debug(): Colon expected, ',' found in %s on line %d
86
87Warning: mysqli_debug(): Colon expected, '1' found in %s on line %d
88
89Warning: mysqli_debug(): Colon expected, '2' found in %s on line %d
90
91Warning: mysqli_debug(): Colon expected, '3' found in %s on line %d
92
93Warning: mysqli_debug(): Unrecognized format 'b' in %s on line %d
94
95Warning: mysqli_debug(): Colon expected, 'B' found in %s on line %d
96
97Warning: mysqli_debug(): Colon expected, 'C' found in %s on line %d
98
99Warning: mysqli_debug(): Colon expected, ',' found in %s on line %d
100
101Warning: mysqli_debug(): Colon expected, '1' found in %s on line %d
102
103Warning: mysqli_debug(): Colon expected, '2' found in %s on line %d
104
105Warning: mysqli_debug(): Colon expected, '3' found in %s on line %d
106
107Warning: mysqli_debug(): Unrecognized format 'b' in %s on line %d
108
109Warning: mysqli_debug(): Colon expected, ';' found in %s on line %d
110
111Warning: mysqli_debug(): Colon expected, ';' found in %s on line %d
112
113Warning: mysqli_debug(): Colon expected, 'B' found in %s on line %d
114
115Warning: mysqli_debug(): Colon expected, 'C' found in %s on line %d
116
117Warning: mysqli_debug(): Colon expected, ',' found in %s on line %d
118
119Warning: mysqli_debug(): Colon expected, '1' found in %s on line %d
120
121Warning: mysqli_debug(): Colon expected, '2' found in %s on line %d
122
123Warning: mysqli_debug(): Colon expected, '3' found in %s on line %d
124
125Warning: mysqli_debug(): Unrecognized format 'b' in %s on line %d
126
127Warning: mysqli_debug(): Colon expected, ';' found in %s on line %d
128
129Warning: mysqli_debug(): Unrecognized format 'z' in %s on line %d
130done%s
131