1--TEST--
2mysqli_stmt_store_result()
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_store_result()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (!is_null($tmp = @mysqli_stmt_store_result($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	if (!is_null($tmp = @mysqli_stmt_store_result(new mysqli_stmt())))
25		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
26
27	if (!$stmt = mysqli_stmt_init($link))
28		printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29
30	// stmt object status test
31	if (NULL !== ($tmp = @mysqli_stmt_store_result($stmt)))
32		printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
33
34	if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100, 'z')") ||
35		!mysqli_stmt_execute($stmt))
36		printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
37
38	if (true !== ($tmp = @mysqli_stmt_store_result($stmt)))
39		printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
40
41	if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test ORDER BY id') ||
42		!mysqli_stmt_execute($stmt))
43		printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
44
45	if (!$link_buf = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
46		printf("[009] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
47
48	if (!$stmt_buf = mysqli_stmt_init($link_buf))
49		printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
50
51	if (!mysqli_stmt_prepare($stmt_buf, "SELECT id, label FROM test ORDER BY id") ||
52		!mysqli_stmt_execute($stmt_buf))
53		printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
54
55	$id = $label = $id_buf = $label_buf = null;
56	if (!mysqli_stmt_bind_result($stmt, $id, $label))
57		printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
58
59	if (!mysqli_stmt_bind_result($stmt_buf, $id_buf, $label_buf))
60		printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
61
62	while (mysqli_stmt_fetch($stmt)) {
63		if (!mysqli_stmt_fetch($stmt_buf)) {
64			printf("[014] Unbuffered statement indicates more rows than buffered, [%d] %s\n",
65				mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
66		}
67		if ($id !== $id_buf)
68			printf("[015] unbuffered '%s'/%s, buffered '%s'/%s\n",
69				$id, gettype($id), $id_buf, gettype($id_buf));
70		if ($label !== $label_buf)
71			printf("[016] unbuffered '%s'/%s, buffered '%s'/%s\n",
72				$label, gettype($label), $label_buf, gettype($label_buf));
73	}
74
75	mysqli_stmt_close($stmt);
76	mysqli_stmt_close($stmt_buf);
77
78	if (NULL !== ($tmp = @mysqli_stmt_store_result($stmt)))
79		printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
80
81	mysqli_close($link);
82	mysqli_close($link_buf);
83	print "done!";
84?>
85--CLEAN--
86<?php
87	require_once("clean_table.inc");
88?>
89--EXPECTF--
90done!
91