xref: /php-src/ext/mysqli/tests/mysqli_info.phpt (revision 7e5171d1)
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 (false === 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 (false === 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 (false === 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 (false === 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 (false === 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 (false === 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
51    // NOTE: no LOAD DATA INFILE test
52    if ($dir = sys_get_temp_dir()) {
53        do {
54            $file = $dir . '/' . 'mysqli_info_phpt.cvs';
55            if (!$fp = fopen($file, 'w'))
56                /* ignore this error */
57                break;
58
59            if (!fwrite($fp, "100;'a';\n") ||
60                !fwrite($fp, "101;'b';\n") ||
61                !fwrite($fp, "102;'c';\n")) {
62                @unlink($file);
63                break;
64            }
65            fclose($fp);
66            if (!mysqli_query($link, "DELETE FROM test")) {
67                printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
68                break;
69            }
70
71            if (!@mysqli_query($link, sprintf("LOAD DATA LOCAL INFILE '%s' INTO TABLE test FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY '\n'", $file))) {
72                /* ok, because we might not be allowed to do this */
73                @unlink($file);
74                break;
75            }
76
77            if (!is_string($tmp = mysqli_info($link)) || ('' == $tmp))
78                printf("[016] Expecting string/any_non_empty, got %s/%s\n", gettype($tmp), $tmp);
79
80            unlink($file);
81        } while (false);
82    }
83
84    print "done!";
85?>
86--CLEAN--
87<?php
88	require_once 'clean_table.inc';
89?>
90--EXPECT--
91done!
92