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