reference/mysqli/mysqli_stmt/affected-rows.xml
2d5c6bed30ea22d847bf03dad1072f075694b4c3
...
...
@@ -4,28 +4,25 @@
4
4
<refnamediv>
5
5
<refname>mysqli_stmt::$affected_rows</refname>
6
6
<refname>mysqli_stmt_affected_rows</refname>
7
-
<refpurpose>Returns the total number of rows changed, deleted, or
8
-
inserted by the last executed statement
7
+
<refpurpose>Returns the total number of rows changed, deleted, inserted, or
8
+
matched by the last statement executed
9
9
</refpurpose>
10
10
</refnamediv>
11
11

12
12
<refsect1 role="description">
13
13
&reftitle.description;
14
14
<para>&style.oop;</para>
15
-
<fieldsynopsis><type>int</type><varname linkend="mysqli-stmt.affected-rows">mysqli_stmt->affected_rows</varname></fieldsynopsis>
15
+
<fieldsynopsis><type class="union"><type>int</type><type>string</type></type><varname linkend="mysqli-stmt.affected-rows">mysqli_stmt-&gt;affected_rows</varname></fieldsynopsis>
16
16
<para>&style.procedural;</para>
17
17
<methodsynopsis>
18
-
<type>int</type><methodname>mysqli_stmt_affected_rows</methodname>
19
-
<methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam>
18
+
<type class="union"><type>int</type><type>string</type></type><methodname>mysqli_stmt_affected_rows</methodname>
19
+
<methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
20
20
</methodsynopsis>
21
21
<para>
22
22
Returns the number of rows affected by <literal>INSERT</literal>,
23
23
<literal>UPDATE</literal>, or <literal>DELETE</literal> query.
24
-
</para>
25
-
<para>
26
-
This function only works with queries which update a table. In order to
27
-
get the number of rows from a SELECT query, use
28
-
<function>mysqli_stmt_num_rows</function> instead.
24
+
Works like <function>mysqli_stmt_num_rows</function> for
25
+
<literal>SELECT</literal> statements.
29
26
</para>
30
27
</refsect1>
31
28

...
...
@@ -42,15 +39,17 @@
42
39
&reftitle.returnvalues;
43
40
<para>
44
41
An integer greater than zero indicates the number of rows affected or
45
-
retrieved.
46
-
Zero indicates that no records where updated for an UPDATE/DELETE
47
-
statement, no rows matched the WHERE clause in the query or that no query
48
-
has yet been executed. -1 indicates that the query has returned an error.
49
-
NULL indicates an invalid argument was supplied to the function.
42
+
retrieved. Zero indicates that no records were updated for an
43
+
<literal>UPDATE</literal> statement, no rows matched the
44
+
<literal>WHERE</literal> clause in the query or that no query has yet been
45
+
executed. <literal>-1</literal> indicates that the query returned an error or
46
+
that, for a <literal>SELECT</literal> query,
47
+
<function>mysqli_stmt_affected_rows</function> was called prior to calling
48
+
<function>mysqli_stmt_store_result</function>.
50
49
</para>
51
50
<note>
52
51
<para>
53
-
If the number of affected rows is greater than maximal PHP int value, the
52
+
If the number of affected rows is greater than maximum PHP int value, the
54
53
number of affected rows will be returned as a string value.
55
54
</para>
56
55
</note>
...
...
@@ -59,17 +58,14 @@
59
58
<refsect1 role="examples">
60
59
&reftitle.examples;
61
60
<example>
62
-
<title>&style.oop;</title>
61
+
<title><methodname>mysqli_stmt_affected_rows</methodname> example</title>
62
+
<para>&style.oop;</para>
63
63
<programlisting role="php">
64
64
<![CDATA[
65
65
<?php
66
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
67
66

68
-
/* check connection */
69
-
if (mysqli_connect_errno()) {
70
-
printf("Connect failed: %s\n", mysqli_connect_error());
71
-
exit();
72
-
}
67
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
68
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
73
69

74
70
/* create temp table */
75
71
$mysqli->query("CREATE TEMPORARY TABLE myCountry LIKE Country");
...
...
@@ -77,39 +73,25 @@ $mysqli->query("CREATE TEMPORARY TABLE myCountry LIKE Country");
77
73
$query = "INSERT INTO myCountry SELECT * FROM Country WHERE Code LIKE ?";
78
74

79
75
/* prepare statement */
80
-
if ($stmt = $mysqli->prepare($query)) {
76
+
$stmt = $mysqli->prepare($query);
81
77

82
-
/* Bind variable for placeholder */
83
-
$code = 'A%';
84
-
$stmt->bind_param("s", $code);
78
+
/* Bind variable for placeholder */
79
+
$code = 'A%';
80
+
$stmt->bind_param("s", $code);
85
81

86
-
/* execute statement */
87
-
$stmt->execute();
82
+
/* execute statement */
83
+
$stmt->execute();
88
84

89
-
printf("rows inserted: %d\n", $stmt->affected_rows);
90
-

91
-
/* close statement */
92
-
$stmt->close();
93
-
}
94
-

95
-
/* close connection */
96
-
$mysqli->close();
97
-
?>
85
+
printf("Rows inserted: %d\n", $stmt->affected_rows);
98
86
]]>
99
87
</programlisting>
100
-
</example>
101
-
<example>
102
-
<title>&style.procedural;</title>
88
+
<para>&style.procedural;</para>
103
89
<programlisting role="php">
104
90
<![CDATA[
105
91
<?php
106
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
107
92

108
-
/* check connection */
109
-
if (mysqli_connect_errno()) {
110
-
printf("Connect failed: %s\n", mysqli_connect_error());
111
-
exit();
112
-
}
93
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
94
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
113
95

114
96
/* create temp table */
115
97
mysqli_query($link, "CREATE TEMPORARY TABLE myCountry LIKE Country");
...
...
@@ -117,30 +99,22 @@ mysqli_query($link, "CREATE TEMPORARY TABLE myCountry LIKE Country");
117
99
$query = "INSERT INTO myCountry SELECT * FROM Country WHERE Code LIKE ?";
118
100

119
101
/* prepare statement */
120
-
if ($stmt = mysqli_prepare($link, $query)) {
102
+
$stmt = mysqli_prepare($link, $query);
121
103

122
-
/* Bind variable for placeholder */
123
-
$code = 'A%';
124
-
mysqli_stmt_bind_param($stmt, "s", $code);
104
+
/* Bind variable for placeholder */
105
+
$code = 'A%';
106
+
mysqli_stmt_bind_param($stmt, "s", $code);
125
107

126
-
/* execute statement */
127
-
mysqli_stmt_execute($stmt);
108
+
/* execute statement */
109
+
mysqli_stmt_execute($stmt);
128
110

129
-
printf("rows inserted: %d\n", mysqli_stmt_affected_rows($stmt));
130
-

131
-
/* close statement */
132
-
mysqli_stmt_close($stmt);
133
-
}
134
-

135
-
/* close connection */
136
-
mysqli_close($link);
137
-
?>
111
+
printf("Rows inserted: %d\n", mysqli_stmt_affected_rows($stmt));
138
112
]]>
139
113
</programlisting>
140
114
&examples.outputs;
141
115
<screen>
142
116
<![CDATA[
143
-
rows inserted: 17
117
+
Rows inserted: 17
144
118
]]>
145
119
</screen>
146
120
</example>
...
...
@@ -151,13 +125,12 @@ rows inserted: 17
151
125
<para>
152
126
<simplelist>
153
127
<member><function>mysqli_stmt_num_rows</function></member>
154
-
<member><function>mysqli_prepare</function></member>
128
+
<member><function>mysqli_stmt_store_result</function></member>
155
129
</simplelist>
156
130
</para>
157
131
</refsect1>
158
132

159
133
</refentry>
160
-

161
134
<!-- Keep this comment at the end of the file
162
135
Local variables:
163
136
mode: sgml
164
137