1--TEST--
2mysqli_stmt_store_result()
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("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
16
17    // stmt object status test
18    try {
19        mysqli_stmt_store_result($stmt);
20    } catch (Error $exception) {
21        echo $exception->getMessage() . "\n";
22    }
23
24    if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100, 'z')") ||
25        !mysqli_stmt_execute($stmt))
26        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
27
28    if (true !== ($tmp = @mysqli_stmt_store_result($stmt)))
29        printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
30
31    if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test ORDER BY id') ||
32        !mysqli_stmt_execute($stmt))
33        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
34
35    if (!$link_buf = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
36        printf("[009] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
37
38    if (!$stmt_buf = mysqli_stmt_init($link_buf))
39        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40
41    if (!mysqli_stmt_prepare($stmt_buf, "SELECT id, label FROM test ORDER BY id") ||
42        !mysqli_stmt_execute($stmt_buf))
43        printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
44
45    $id = $label = $id_buf = $label_buf = null;
46    if (!mysqli_stmt_bind_result($stmt, $id, $label))
47        printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
48
49    if (!mysqli_stmt_bind_result($stmt_buf, $id_buf, $label_buf))
50        printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
51
52    while (mysqli_stmt_fetch($stmt)) {
53        if (!mysqli_stmt_fetch($stmt_buf)) {
54            printf("[014] Unbuffered statement indicates more rows than buffered, [%d] %s\n",
55                mysqli_stmt_errno($stmt_buf), mysqli_stmt_error($stmt_buf));
56        }
57        if ($id !== $id_buf)
58            printf("[015] unbuffered '%s'/%s, buffered '%s'/%s\n",
59                $id, gettype($id), $id_buf, gettype($id_buf));
60        if ($label !== $label_buf)
61            printf("[016] unbuffered '%s'/%s, buffered '%s'/%s\n",
62                $label, gettype($label), $label_buf, gettype($label_buf));
63    }
64
65    mysqli_stmt_close($stmt);
66    mysqli_stmt_close($stmt_buf);
67
68    try {
69        mysqli_stmt_store_result($stmt);
70    } catch (Error $exception) {
71        echo $exception->getMessage() . "\n";
72    }
73
74    mysqli_close($link);
75    mysqli_close($link_buf);
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