1--TEST--
2mysqli_stmt_reset()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    // Note: No SQL tests here! We can expand one of the *fetch()
14    // tests to a generic SQL test, if we ever need that.
15    // We would duplicate the SQL test cases if we have it here and in one of the
16    // fetch tests, because the fetch tests would have to call prepare/execute etc.
17    // anyway.
18
19    require('table.inc');
20
21    if (!$stmt = mysqli_stmt_init($link))
22        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24    try {
25        mysqli_stmt_reset($stmt);
26    } catch (Error $exception) {
27        echo $exception->getMessage() . "\n";
28    }
29
30    if (true !== ($tmp = mysqli_stmt_prepare($stmt, 'SELECT id FROM test')))
31        printf("[005] Expecting boolean/true, got %s/%s, [%d] %s\n",
32            gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
33
34    if (true !== ($tmp = mysqli_stmt_reset($stmt)))
35        printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
36
37    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
38        printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
39
40    $id = null;
41    if (!mysqli_stmt_bind_result($stmt, $id))
42        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
43
44    if (!mysqli_stmt_fetch($stmt))
45        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
46
47    var_dump($id);
48    mysqli_stmt_close($stmt);
49    if (!$stmt = mysqli_stmt_init($link))
50        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
51
52    if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
53        printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54
55    if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label BLOB, PRIMARY KEY(id))"))
56        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(label) VALUES (?)"))
59        printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
60
61    $label = null;
62    if (!mysqli_stmt_bind_param($stmt, "b", $label))
63        printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
64
65    $label = 'abc';
66    for ($i = 0; $i < 10; $i++) {
67        if (!mysqli_stmt_send_long_data($stmt, 0, $label))
68            printf("[015 - %d] [%d] %s\n", $i, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
69    }
70
71    if (!mysqli_stmt_reset($stmt))
72        printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
73
74    if (!mysqli_stmt_execute($stmt))
75        printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
76
77    if (!$res = mysqli_query($link, "SELECT label FROM test"))
78        printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
79
80    if (!$row = mysqli_fetch_assoc($res))
81        printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
82
83    mysqli_free_result($res);
84
85    if ($row['label'] != '')
86        printf("[020] Expecting empty string, got string/%s\n", $row['label']);
87
88    mysqli_stmt_close($stmt);
89
90    try {
91        mysqli_stmt_reset($stmt);
92    } catch (Error $exception) {
93        echo $exception->getMessage() . "\n";
94    }
95
96    mysqli_close($link);
97    print "done!";
98?>
99--CLEAN--
100<?php
101    require_once("clean_table.inc");
102?>
103--EXPECT--
104mysqli_stmt object is not fully initialized
105int(1)
106mysqli_stmt object is already closed
107done!
108