reference/mysqli/mysqli_stmt/get-result.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -1,28 +1,42 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="mysqli-stmt.get-result" xmlns="http://docbook.org/ns/docbook">
5
4
<refnamediv>
6
5
<refname>mysqli_stmt::get_result</refname>
7
6
<refname>mysqli_stmt_get_result</refname>
8
-
<refpurpose>Gets a result set from a prepared statement</refpurpose>
7
+
<refpurpose>Gets a result set from a prepared statement as a <classname>mysqli_result</classname> object</refpurpose>
9
8
</refnamediv>
10
9

11
10
<refsect1 role="description">
12
11
&reftitle.description;
13
12
<para>&style.oop;</para>
14
-
<methodsynopsis role="oop">
15
-
<type>mysqli_result</type><methodname>mysqli_stmt::get_result</methodname>
16
-
<void />
13
+
<methodsynopsis role="mysqli_stmt">
14
+
<modifier>public</modifier> <type class="union"><type>mysqli_result</type><type>false</type></type><methodname>mysqli_stmt::get_result</methodname>
15
+
<void/>
17
16
</methodsynopsis>
18
17
<para>&style.procedural;</para>
19
18
<methodsynopsis>
20
-
<type>mysqli_result</type><methodname>mysqli_stmt_get_result</methodname>
21
-
<methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam>
19
+
<type class="union"><type>mysqli_result</type><type>false</type></type><methodname>mysqli_stmt_get_result</methodname>
20
+
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
22
21
</methodsynopsis>
23
22
<para>
24
-
Call to return a result set from a prepared statement query.
23
+
Retrieves a result set from a prepared statement as a
24
+
<classname>mysqli_result</classname> object. The data will be fetched from
25
+
the MySQL server to PHP. This method should be called only for
26
+
queries which produce a result set.
25
27
</para>
28
+
<note>
29
+
<para>
30
+
&mysqli.available.mysqlnd;
31
+
</para>
32
+
</note>
33
+
<note>
34
+
<para>
35
+
This function cannot be used together
36
+
with <function>mysqli_stmt_store_result</function>. Both of these functions
37
+
retrieve the full result set from the MySQL server.
38
+
</para>
39
+
</note>
26
40
</refsect1>
27
41

28
42
<refsect1 role="parameters">
...
...
@@ -37,18 +51,18 @@
37
51
<refsect1 role="returnvalues">
38
52
&reftitle.returnvalues;
39
53
<para>
40
-
Returns a resultset for successful SELECT queries, or &false; for other DML
41
-
queries or on failure. The <function>mysqli_errno</function> function can be
42
-
used to distinguish between the two types of failure.
54
+
Returns &false; on failure. For successful queries which produce a result set, such as <literal>SELECT, SHOW, DESCRIBE</literal> or
55
+
<literal>EXPLAIN</literal>, <function>mysqli_stmt_get_result</function> will return
56
+
a <classname>mysqli_result</classname> object. For other successful queries, <function>mysqli_stmt_get_result</function> will
57
+
return &false;. The <function>mysqli_stmt_errno</function> function can be
58
+
used to distinguish between the two reasons for &false;; due to a bug, prior to PHP 7.4.13,
59
+
<function>mysqli_errno</function> had to be used for this purpose.
43
60
</para>
44
61
</refsect1>
45
62

46
-
<refsect1 role="mysqlnd">
47
-
&reftitle.mysqlnd;
48
-

49
-
<para>
50
-
&mysqli.available.mysqlnd;
51
-
</para>
63
+
<refsect1 role="errors">
64
+
&reftitle.errors;
65
+
&mysqli.conditionalexception;
52
66
</refsect1>
53
67

54
68
<refsect1 role="examples">
...
...
@@ -59,44 +73,26 @@
59
73
<![CDATA[
60
74
<?php
61
75

62
-
$mysqli = new mysqli("127.0.0.1", "user", "password", "world");
63
-

64
-
if($mysqli->connect_error)
65
-
{
66
-
die("$mysqli->connect_errno: $mysqli->connect_error");
67
-
}
76
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
77
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
68
78

69
79
$query = "SELECT Name, Population, Continent FROM Country WHERE Continent=? ORDER BY Name LIMIT 1";
70
80

71
-
$stmt = $mysqli->stmt_init();
72
-
if(!$stmt->prepare($query))
73
-
{
74
-
print "Failed to prepare statement\n";
75
-
}
76
-
else
77
-
{
78
-
$stmt->bind_param("s", $continent);
79
-

80
-
$continent_array = array('Europe','Africa','Asia','North America');
81
-

82
-
foreach($continent_array as $continent)
83
-
{
84
-
$stmt->execute();
85
-
$result = $stmt->get_result();
86
-
while ($row = $result->fetch_array(MYSQLI_NUM))
87
-
{
88
-
foreach ($row as $r)
89
-
{
90
-
print "$r ";
91
-
}
92
-
print "\n";
81
+
$stmt = $mysqli->prepare($query);
82
+
$stmt->bind_param("s", $continent);
83
+

84
+
$continentList = array('Europe', 'Africa', 'Asia', 'North America');
85
+

86
+
foreach ($continentList as $continent) {
87
+
$stmt->execute();
88
+
$result = $stmt->get_result();
89
+
while ($row = $result->fetch_array(MYSQLI_NUM)) {
90
+
foreach ($row as $r) {
91
+
print "$r ";
93
92
}
93
+
print "\n";
94
94
}
95
95
}
96
-

97
-
$stmt->close();
98
-
$mysqli->close();
99
-
?>
100
96
]]>
101
97
</programlisting>
102
98
</example>
...
...
@@ -106,49 +102,29 @@ $mysqli->close();
106
102
<![CDATA[
107
103
<?php
108
104

109
-
$link = mysqli_connect("127.0.0.1", "user", "password", "world");
110
-

111
-
if (!$link)
112
-
{
113
-
$error = mysqli_connect_error();
114
-
$errno = mysqli_connect_errno();
115
-
print "$errno: $error\n";
116
-
exit();
117
-
}
105
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
106
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
118
107

119
108
$query = "SELECT Name, Population, Continent FROM Country WHERE Continent=? ORDER BY Name LIMIT 1";
120
109

121
-
$stmt = mysqli_stmt_init($link);
122
-
if(!mysqli_stmt_prepare($stmt, $query))
123
-
{
124
-
print "Failed to prepare statement\n";
125
-
}
126
-
else
127
-
{
128
-
mysqli_stmt_bind_param($stmt, "s", $continent);
129
-

130
-
$continent_array = array('Europe','Africa','Asia','North America');
131
-

132
-
foreach($continent_array as $continent)
133
-
{
134
-
mysqli_stmt_execute($stmt);
135
-
$result = mysqli_stmt_get_result($stmt);
136
-
while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
137
-
{
138
-
foreach ($row as $r)
139
-
{
140
-
print "$r ";
141
-
}
142
-
print "\n";
110
+
$stmt = mysqli_prepare($link, $query);
111
+
mysqli_stmt_bind_param($stmt, "s", $continent);
112
+

113
+
$continentList= array('Europe', 'Africa', 'Asia', 'North America');
114
+

115
+
foreach ($continentList as $continent) {
116
+
mysqli_stmt_execute($stmt);
117
+
$result = mysqli_stmt_get_result($stmt);
118
+
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
119
+
foreach ($row as $r) {
120
+
print "$r ";
143
121
}
122
+
print "\n";
144
123
}
145
124
}
146
-
mysqli_stmt_close($stmt);
147
-
mysqli_close($link);
148
-
?>
149
125
]]>
150
126
</programlisting>
151
-
&examples.outputs;
127
+
&examples.outputs.similar;
152
128
<screen>
153
129
<![CDATA[
154
130
Albania 3401200 Europe
...
...
@@ -169,13 +145,11 @@ Anguilla 8000 North America
169
145
<member><function>mysqli_stmt_fetch</function></member>
170
146
<member><function>mysqli_fetch_array</function></member>
171
147
<member><function>mysqli_stmt_store_result</function></member>
172
-
<member><function>mysqli_errno</function></member>
173
148
</simplelist>
174
149
</para>
175
150
</refsect1>
176
151

177
152
</refentry>
178
-

179
153
<!-- Keep this comment at the end of the file
180
154
Local variables:
181
155
mode: sgml
182
156