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