1--TEST--
2mysqli_stmt_reset()
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	// 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	$tmp    = NULL;
20	$link   = NULL;
21
22	if (!is_null($tmp = @mysqli_stmt_reset()))
23		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
24
25	if (!is_null($tmp = @mysqli_stmt_reset($link)))
26		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
27
28	require('table.inc');
29
30	if (!$stmt = mysqli_stmt_init($link))
31		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
32
33	if (NULL !== ($tmp = mysqli_stmt_reset($stmt)))
34		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
35
36	if (true !== ($tmp = mysqli_stmt_prepare($stmt, 'SELECT id FROM test')))
37		printf("[005] Expecting boolean/true, got %s/%s, [%d] %s\n",
38			gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
39
40	if (true !== ($tmp = mysqli_stmt_reset($stmt)))
41		printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
42
43	if (true !== ($tmp = mysqli_stmt_execute($stmt)))
44		printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
45
46	$id = null;
47	if (!mysqli_stmt_bind_result($stmt, $id))
48		printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
49
50	if (!mysqli_stmt_fetch($stmt))
51		printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
52
53	var_dump($id);
54	mysqli_stmt_close($stmt);
55	if (!$stmt = mysqli_stmt_init($link))
56		printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58	if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
59		printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
60
61	if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT, label BLOB, PRIMARY KEY(id))"))
62		printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63
64	if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(label) VALUES (?)"))
65		printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
66
67	$label = null;
68	if (!mysqli_stmt_bind_param($stmt, "b", $label))
69		printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
70
71	$label = 'abc';
72	for ($i = 0; $i < 10; $i++) {
73		if (!mysqli_stmt_send_long_data($stmt, 0, $label))
74			printf("[015 - %d] [%d] %s\n", $i, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
75	}
76
77	if (!mysqli_stmt_reset($stmt))
78		printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
79
80	if (!mysqli_stmt_execute($stmt))
81		printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
82
83	if (!$res = mysqli_query($link, "SELECT label FROM test"))
84		printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
85
86	if (!$row = mysqli_fetch_assoc($res))
87		printf("[019] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
88
89	mysqli_free_result($res);
90
91	if ($row['label'] != '')
92		printf("[020] Expecting empty string, got string/%s\n", $row['label']);
93
94	mysqli_stmt_close($stmt);
95
96	if (NULL !== ($tmp = mysqli_stmt_reset($stmt)))
97		printf("[021] Expecting NULL, got %s/%s\n");
98
99	mysqli_close($link);
100	print "done!";
101?>
102--CLEAN--
103<?php
104	require_once("clean_table.inc");
105?>
106--EXPECTF--
107Warning: mysqli_stmt_reset(): invalid object or resource mysqli_stmt
108 in %s on line %d
109int(1)
110
111Warning: mysqli_stmt_reset(): Couldn't fetch mysqli_stmt in %s on line %d
112done!