1--TEST--
2mysqli_debug() - invalid debug control strings
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
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 (!$IS_MYSQLND)
19	die("SKIP Libmysql feature not sufficiently spec'd in MySQL C API documentation");
20?>
21--FILE--
22<?php
23	require_once('connect.inc');
24	require_once('table.inc');
25
26	function try_control_string($link, $control_string, $trace_file, $offset) {
27
28		if (true !== ($tmp = mysqli_debug($control_string))) {
29			printf("[%03d][control string '%s'] Expecting boolean/true, got %s/%s.\n",
30				$offset + 1,
31				$control_string,
32				gettype($tmp),
33				$tmp);
34			return false;
35		}
36
37		if (!$res = mysqli_query($link, 'SELECT * FROM test')) {
38			printf("[%03d][control string '%s'] [%d] %s.\n",
39				$offset + 2,
40				$control_string,
41				mysqli_errno($link),
42				mysqli_error($link));
43			return false;
44		}
45
46		clearstatcache();
47		if (!file_exists($trace_file)) {
48			printf("[%03d][control string '%s'] Trace file has not been written.\n",
49				$offset + 3,
50				$control_string,
51				gettype($tmp),
52				$tmp);
53			return false;
54		}
55
56		unlink($trace_file);
57	}
58
59	$trace_file = sprintf('%s%s%s', sys_get_temp_dir(), DIRECTORY_SEPARATOR, 'mysqli_debug_phpt.trace');
60	try_control_string($link, 't:,,:o,' . $trace_file, $trace_file, 10);
61	try_control_string($link, ':' . chr(0) . 'A,' . $trace_file, $trace_file, 20);
62	try_control_string($link, 't:o,' . $trace_file . ':abc', $trace_file, 30);
63	try_control_string($link, 't:o,' . $trace_file . ':ABC,123:b', $trace_file, 40);
64	try_control_string($link, 't:ABC,123:b;:o,' . $trace_file, $trace_file, 50);
65	try_control_string($link, 't:A;BC,123:b;:o,' . $trace_file, $trace_file, 60);
66	try_control_string($link, 't:p:o,' . $trace_file, $trace_file, 70);
67	try_control_string($link, 't:p,1,,2:o,' . $trace_file, $trace_file, 80);
68	try_control_string($link, 't:z,1,,2:o,' . $trace_file, $trace_file, 90);#
69
70	mysqli_close($link);
71	print "done";
72	if ($IS_MYSQLND)
73		print "libmysql/DBUG package prints some debug info here."
74?>
75--EXPECTF--
76[023][control string '%s'] Trace file has not been written.
77done%s
78