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