xref: /PHP-7.1/ext/mysqli/tests/mysqli_info.phpt (revision 113213f0)
1--TEST--
2mysqli_info()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	if (!is_null($tmp = @mysqli_info()))
14		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
15
16	if (!is_null($tmp = @mysqli_info(NULL)))
17		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	require "table.inc";
20	if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, 'a')"))
21		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23	// NOTE: empty string, no multiple insert syntax
24	if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp))
25		printf("[004] Expecting null, got %s/%s\n", gettype($tmp), $tmp);
26
27	if (!$res = mysqli_query($link, "INSERT INTO test(id, label) VALUES (101, 'a'), (102, 'b')"))
28		printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29
30	if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
31		printf("[006] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
32
33	if ((version_compare(PHP_VERSION, '6.0', '==') == 1) &&
34	    !is_unicode($tmp))
35		printf("[007] Expecting unicode, because unicode mode it on. Got binary string\n");
36
37	if (!$res = mysqli_query($link, 'INSERT INTO test(id, label) SELECT id + 200, label FROM test'))
38		printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
39
40	if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
41		printf("[008] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
42
43	if (!$res = mysqli_query($link, 'ALTER TABLE test MODIFY label CHAR(2)'))
44		printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
45
46	if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
47		printf("[010] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
48
49	if (!$res = mysqli_query($link, "UPDATE test SET label = 'b' WHERE id >= 100"))
50		printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
51
52	if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
53		printf("[012] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
54
55	if (!$res = mysqli_query($link, "SELECT 1"))
56		printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58	if (!is_null($tmp = mysqli_info($link)) || ('' != $tmp))
59		printf("[014] Expecting null, got %s/%s\n", gettype($tmp), $tmp);
60	mysqli_free_result($res);
61
62	// NOTE: no LOAD DATA INFILE test
63	if ($dir = sys_get_temp_dir()) {
64		do {
65			$file = $dir . '/' . 'mysqli_info_phpt.cvs';
66			if (!$fp = fopen($file, 'w'))
67				/* ignore this error */
68				break;
69
70			if (!fwrite($fp, b"100;'a';\n") ||
71				!fwrite($fp, b"101;'b';\n") ||
72				!fwrite($fp, b"102;'c';\n")) {
73				@unlink($file);
74				break;
75			}
76			fclose($fp);
77			if (!mysqli_query($link, "DELETE FROM test")) {
78				printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
79				break;
80			}
81
82			if (!@mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY '\n'", $file))) {
83				/* ok, because we might not be allowed to do this */
84				@unlink($file);
85				break;
86			}
87
88			if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
89				printf("[016] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
90
91			unlink($file);
92		} while (false);
93	}
94
95	print "done!";
96?>
97--CLEAN--
98<?php
99	require_once("clean_table.inc");
100?>
101--EXPECTF--
102done!
103