reference/mysqli/mysqli_stmt/get-result.xml
63b99082ef83eade08151f8cb528246fded81db9
...
...
@@ -4,29 +4,39 @@
4
4
<refnamediv>
5
5
<refname>mysqli_stmt::get_result</refname>
6
6
<refname>mysqli_stmt_get_result</refname>
7
-
<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>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
12
<para>&style.oop;</para>
13
-
<methodsynopsis role="oop">
13
+
<methodsynopsis role="mysqli_stmt">
14
14
<modifier>public</modifier> <type class="union"><type>mysqli_result</type><type>false</type></type><methodname>mysqli_stmt::get_result</methodname>
15
15
<void/>
16
16
</methodsynopsis>
17
17
<para>&style.procedural;</para>
18
-
<methodsynopsis role="procedural">
18
+
<methodsynopsis>
19
19
<type class="union"><type>mysqli_result</type><type>false</type></type><methodname>mysqli_stmt_get_result</methodname>
20
20
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
21
21
</methodsynopsis>
22
22
<para>
23
-
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.
24
27
</para>
25
28
<note>
26
29
<para>
27
30
&mysqli.available.mysqlnd;
28
31
</para>
29
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>
30
40
</refsect1>
31
41

32
42
<refsect1 role="parameters">
...
...
@@ -50,6 +60,11 @@
50
60
</para>
51
61
</refsect1>
52
62

63
+
<refsect1 role="errors">
64
+
&reftitle.errors;
65
+
&mysqli.conditionalexception;
66
+
</refsect1>
67
+

53
68
<refsect1 role="examples">
54
69
&reftitle.examples;
55
70
<example>
...
...
@@ -58,44 +73,26 @@
58
73
<![CDATA[
59
74
<?php
60
75

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

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

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

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

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

81
-
foreach($continent_array as $continent)
82
-
{
83
-
$stmt->execute();
84
-
$result = $stmt->get_result();
85
-
while ($row = $result->fetch_array(MYSQLI_NUM))
86
-
{
87
-
foreach ($row as $r)
88
-
{
89
-
print "$r ";
90
-
}
91
-
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 ";
92
92
}
93
+
print "\n";
93
94
}
94
95
}
95
-

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

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

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

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

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

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

131
-
foreach($continent_array as $continent)
132
-
{
133
-
mysqli_stmt_execute($stmt);
134
-
$result = mysqli_stmt_get_result($stmt);
135
-
while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
136
-
{
137
-
foreach ($row as $r)
138
-
{
139
-
print "$r ";
140
-
}
141
-
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 ";
142
121
}
122
+
print "\n";
143
123
}
144
124
}
145
-
mysqli_stmt_close($stmt);
146
-
mysqli_close($link);
147
-
?>
148
125
]]>
149
126
</programlisting>
150
-
&examples.outputs;
127
+
&examples.outputs.similar;
151
128
<screen>
152
129
<![CDATA[
153
130
Albania 3401200 Europe
...
...
@@ -168,7 +145,6 @@ Anguilla 8000 North America
168
145
<member><function>mysqli_stmt_fetch</function></member>
169
146
<member><function>mysqli_fetch_array</function></member>
170
147
<member><function>mysqli_stmt_store_result</function></member>
171
-
<member><function>mysqli_errno</function></member>
172
148
</simplelist>
173
149
</para>
174
150
</refsect1>
175
151