1--TEST--
2mysqli_report(), MySQL < 5.6
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once "connect.inc";
8
9if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
10    die(sprintf("SKIP Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
11        $host, $user, $db, $port, $socket));
12
13if (mysqli_get_server_version($link) >= 50600)
14    die("SKIP For MySQL < 5.6.0");
15?>
16--FILE--
17<?php
18    if (true !== ($tmp = mysqli_report(-1)))
19        printf("[002] Expecting boolean/true even for invalid flags, got %s/%s\n", gettype($tmp), $tmp);
20
21    if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ERROR)))
22        printf("[003] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
23
24    if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_STRICT)))
25        printf("[004] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
26
27    if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_INDEX)))
28        printf("[005] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
29
30    if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_ALL)))
31        printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
32
33    if (true !== ($tmp = mysqli_report(MYSQLI_REPORT_OFF)))
34        printf("[008] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
35
36    require 'table.inc';
37
38    /*
39    Internal macro MYSQL_REPORT_ERROR
40    */
41    mysqli_report(MYSQLI_REPORT_ERROR);
42
43    mysqli_multi_query($link, "BAR; FOO;");
44    mysqli_query($link, "FOO");
45    mysqli_change_user($link, "0123456789-10-456789-20-456789-30-456789-40-456789-50-456789-60-456789-70-456789-80-456789-90-456789", "password", $db);
46    try {
47        mysqli_kill($link, -1);
48    } catch (\ValueError $e) {
49        echo $e->getMessage() . \PHP_EOL;
50    }
51
52    // mysqli_ping() cannot be tested, because one would need to cause an error inside the C function to test it
53    mysqli_real_query($link, "FOO");
54    if (@mysqli_select_db($link, "Oh lord, let this be an unknown database name"))
55        printf("[009] select_db should have failed\n");
56    // mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it
57
58
59    // Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would
60    // not have been set. If that would be the case, the test would be broken.
61    mysqli_report(MYSQLI_REPORT_OFF);
62
63    mysqli_multi_query($link, "BAR; FOO;");
64    mysqli_query($link, "FOO");
65    mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
66    try {
67        mysqli_kill($link, -1);
68    } catch (\ValueError $e) {
69        echo $e->getMessage() . \PHP_EOL;
70    }
71    mysqli_real_query($link, "FOO");
72    mysqli_select_db($link, "Oh lord, let this be an unknown database name");
73
74    mysqli_report(MYSQLI_REPORT_OFF);
75    mysqli_report(MYSQLI_REPORT_STRICT);
76
77    try {
78
79        if ($link = my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
80            printf("[010] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
81                $host, $user . 'unknown_really', $db, $port, $socket);
82        mysqli_close($link);
83
84    } catch (mysqli_sql_exception $e) {
85        printf("[011] %s\n", $e->getMessage());
86    }
87
88    try {
89        if (!$link = mysqli_init())
90            printf("[012] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
91
92        if ($link = my_mysqli_real_connect($link, $host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket))
93            printf("[013] Can connect to the server using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
94                $host, $user . 'unknown_really', $db, $port, $socket);
95        mysqli_close($link);
96    } catch (mysqli_sql_exception $e) {
97        printf("[014] %s\n", $e->getMessage());
98    }
99
100    print "done!";
101?>
102--CLEAN--
103<?php
104require_once "clean_table.inc";
105?>
106--EXPECTF--
107Warning: mysqli_multi_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'BAR; FOO' at line 1 in %s on line %d
108
109Warning: mysqli_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
110
111Warning: mysqli_change_user(): (%d/%d): Access denied for user '%s'@'%s' (using password: %s) in %s on line %d
112mysqli_kill(): Argument #2 ($process_id) must be greater than 0
113
114Warning: mysqli_real_query(): (%d/%d): You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'FOO' at line 1 in %s on line %d
115mysqli_kill(): Argument #2 ($process_id) must be greater than 0
116[011] Access denied for user '%s'@'%s' (using password: YES)
117[014] Access denied for user '%s'@'%s' (using password: YES)
118done!
119