1--TEST--
2mysqli_stmt_get_result()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    /*
12    NOTE: no datatype tests here! This is done by
13    mysqli_stmt_bind_result.phpt already. Restrict
14    this test case to the basics.
15    */
16    require 'table.inc';
17
18    if (!$stmt = mysqli_stmt_init($link))
19        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20
21    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 1"))
22        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
23
24        if (!mysqli_stmt_execute($stmt))
25            printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
26
27        if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
28            printf("[007] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
29                gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
30        }
31        while ($row = mysqli_fetch_assoc($res))
32            var_dump($row);
33        var_dump(mysqli_fetch_assoc($res));
34        mysqli_free_result($res);
35
36        if (false !== ($res = mysqli_stmt_get_result($stmt))) {
37            printf("[008] boolean/false got %s/%s, [%d] %s\n",
38                gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
39        }
40
41        mysqli_stmt_execute($stmt);
42        if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
43            printf("[009] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
44                gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
45        }
46        while ($row = mysqli_fetch_assoc($res))
47            var_dump($row);
48        var_dump(mysqli_fetch_assoc($res));
49        mysqli_free_result($res);
50
51    mysqli_stmt_close($stmt);
52
53    if (!($stmt = mysqli_stmt_init($link)) ||
54        !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
55        !mysqli_stmt_execute($stmt))
56        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
57
58    $id = $label = null;
59    if (!mysqli_stmt_bind_result($stmt, $id, $label))
60        printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62    if (!mysqli_stmt_fetch($stmt))
63        printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
64
65    if (false !== ($res = mysqli_stmt_get_result($stmt))) {
66        printf("[013] boolean/false got %s/%s, [%d] %s\n",
67            gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
68    }
69
70    mysqli_stmt_close($stmt);
71
72    if (!($stmt = mysqli_stmt_init($link)) ||
73        !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
74        !mysqli_stmt_execute($stmt))
75        printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
76
77    if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
78        printf("[015] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
79            gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
80    }
81
82    $id = $label = null;
83    if (!mysqli_stmt_bind_result($stmt, $id, $label))
84        printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
85
86    if (!mysqli_stmt_fetch($stmt))
87        printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
88
89    mysqli_stmt_close($stmt);
90
91    if (!($stmt = mysqli_stmt_init($link)) ||
92        !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
93        !mysqli_stmt_execute($stmt))
94        printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
95
96    if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
97        printf("[019] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
98            gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
99    }
100
101    $id = $label = null;
102    if (!mysqli_stmt_bind_result($stmt, $id, $label))
103        printf("[020] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
104
105    mysqli_fetch_assoc($res);
106    if (NULL !== $id || NULL !== $label)
107        printf("[021] Bound variables should not have been set\n");
108    mysqli_free_result($res);
109
110    mysqli_stmt_close($stmt);
111
112    if (!($stmt = mysqli_stmt_init($link)) ||
113        !mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id ASC LIMIT 2") ||
114        !mysqli_stmt_execute($stmt))
115        printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
116
117    if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
118        printf("[023] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
119            gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
120    }
121    if (!in_array($res->type, array(MYSQLI_STORE_RESULT, MYSQLI_USE_RESULT))) {
122        printf("[024] Unknown result set type %s\n", $res->type);
123    }
124    if ($res->type !== MYSQLI_STORE_RESULT)
125        printf("[025] Expecting int/%d got %s/%s", MYSQLI_STORE_RESULT, gettype($res->type), $res->type);
126
127    mysqli_free_result($res);
128    mysqli_stmt_close($stmt);
129    mysqli_close($link);
130
131    try {
132        mysqli_stmt_get_result($stmt);
133    } catch (Error $exception) {
134        echo $exception->getMessage() . "\n";
135    }
136
137    print "done!";
138?>
139--CLEAN--
140<?php
141    require_once 'clean_table.inc';
142?>
143--EXPECT--
144array(2) {
145  ["id"]=>
146  int(1)
147  ["label"]=>
148  string(1) "a"
149}
150NULL
151array(2) {
152  ["id"]=>
153  int(1)
154  ["label"]=>
155  string(1) "a"
156}
157NULL
158[017] [2014] Commands out of sync; you can't run this command now
159mysqli_stmt object is already closed
160done!
161