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