1--TEST--
2mysqli_stmt_close()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    require('table.inc');
13
14    if (!$stmt = mysqli_stmt_init($link))
15        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
16
17    // Yes, amazing, eh? AFAIK a work around of a constructor bug...
18    try {
19        mysqli_stmt_close($stmt);
20    } catch (Error $exception) {
21        echo $exception->getMessage() . "\n";
22    }
23
24    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
25        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
26
27    if (true !== ($tmp = mysqli_stmt_close($stmt)))
28        printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
29
30    try {
31        mysqli_stmt_close($stmt);
32    } catch (Error $exception) {
33        echo $exception->getMessage() . "\n";
34    }
35
36    if (!$stmt = mysqli_stmt_init($link))
37        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38
39    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
40        printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
41
42    $id = $label = null;
43    if (!mysqli_stmt_bind_param($stmt, "is", $id, $label))
44        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
45
46    $id = 100; $label = 'z';
47    if (!mysqli_stmt_execute($stmt))
48        printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
49
50    mysqli_kill($link, mysqli_thread_id($link));
51
52    if (true !== ($tmp = mysqli_stmt_close($stmt)))
53        printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
54
55    mysqli_close($link);
56
57    require('table.inc');
58    if (!$stmt = mysqli_stmt_init($link))
59        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
60
61    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
62        printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
63
64    $id = $label = null;
65    if (!mysqli_stmt_bind_result($stmt, $id, $label))
66        printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
67
68    if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt))
69        printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
70
71    mysqli_kill($link, mysqli_thread_id($link));
72
73    if (true !== ($tmp = mysqli_stmt_close($stmt)))
74        printf("[017] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
75
76    print "done!";
77?>
78--CLEAN--
79<?php
80    require_once("clean_table.inc");
81?>
82--EXPECT--
83mysqli_stmt object is not fully initialized
84mysqli_stmt object is already closed
85done!
86