1--TEST--
2mysqli_stmt_get_warnings() - TODO
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8
9require_once("connect.inc");
10
11if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
12    die(sprintf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
13        $host, $user, $db, $port, $socket));
14}
15
16if (!mysqli_query($link, "DROP TABLE IF EXISTS test") ||
17    !mysqli_query($link, "CREATE TABLE test(id SMALLINT)"))
18    die(sprintf("skip [%d] %s\n", $link->errno, $link->error));
19
20if (!@mysqli_query($link, "SET sql_mode=''") || !@mysqli_query($link, "INSERT INTO test(id) VALUES (100001)"))
21    die("skip Strict sql mode seems to be active. We won't get a warning to check for.");
22
23mysqli_query($link, "DROP TABLE IF EXISTS test");
24?>
25--FILE--
26<?php
27    require_once("connect.inc");
28
29    require('table.inc');
30
31    if (!$stmt = mysqli_stmt_init($link))
32        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
33
34    try {
35        mysqli_stmt_get_warnings($stmt);
36    } catch (Error $exception) {
37        echo $exception->getMessage() . "\n";
38    }
39
40    if (!mysqli_stmt_prepare($stmt, "SET sql_mode=''") || !mysqli_stmt_execute($stmt))
41        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
42
43    if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") || !mysqli_stmt_execute($stmt))
44        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
45
46    if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
47        printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
48
49    if (!mysqli_stmt_prepare($stmt, "CREATE TABLE test(id SMALLINT, label CHAR(1))") || !mysqli_stmt_execute($stmt))
50        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
51
52    if (false !== ($tmp = mysqli_stmt_get_warnings($stmt)))
53        printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
54
55    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100000, 'a'), (100001, 'b')") ||
56        !mysqli_stmt_execute($stmt))
57        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
58
59    if (!is_object($warning = mysqli_stmt_get_warnings($stmt)))
60        printf("[011] Expecting mysqli_warning object, got %s/%s\n", gettype($warning), $warning);
61
62    if ('mysqli_warning' !== get_class($warning))
63        printf("[012] Expecting object of type mysqli_warning got type '%s'", get_class($warning));
64
65    if (!method_exists($warning, 'next'))
66        printf("[013] Object mysqli_warning seems to lack method next()\n");
67
68    $i = 0;
69    do {
70
71        if ('' == $warning->message)
72            printf("[014 - %d] Message should not be empty\n", $i);
73
74        if ('' == $warning->sqlstate)
75            printf("[015 - %d] SQL State should not be empty\n", $i);
76
77        if (0 == $warning->errno)
78            printf("[016 - %d] Error number should not be zero\n", $i);
79
80        $i++;
81
82    } while ($warning->next());
83
84    if (2 != $i)
85        printf("[017] Expected 2 warnings, got %d warnings\n", $i);
86
87    mysqli_stmt_close($stmt);
88
89    try {
90        mysqli_stmt_get_warnings($stmt);
91    } catch (Error $exception) {
92        echo $exception->getMessage() . "\n";
93    }
94
95    mysqli_close($link);
96    print "done!";
97?>
98--CLEAN--
99<?php
100    require_once("clean_table.inc");
101?>
102--EXPECT--
103mysqli_stmt object is not fully initialized
104mysqli_stmt object is already closed
105done!
106