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