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