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