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