reference/mysqli/mysqli/affected-rows.xml
9ed7c3ebf7ab6929d2fd367734a5d72b16cfc128
...
...
@@ -2,31 +2,26 @@
2
2
<!-- $Revision$ -->
3
3
<refentry xml:id="mysqli.affected-rows" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
-
<refname>mysqli->affected_rows</refname>
5
+
<refname>mysqli::$affected_rows</refname>
6
6
<refname>mysqli_affected_rows</refname>
7
7
<refpurpose>Gets the number of affected rows in a previous MySQL operation</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
11
11
&reftitle.description;
12
-
<para>Object oriented style (property):</para>
13
-
<classsynopsis>
14
-
<ooclass><classname>mysqli</classname></ooclass>
15
-
<fieldsynopsis><type>int</type><varname>affected_rows</varname></fieldsynopsis>
16
-
</classsynopsis>
17
-
<para>Procedural style:</para>
12
+
<para>&style.oop;</para>
13
+
<fieldsynopsis><type class="union"><type>int</type><type>string</type></type><varname linkend="mysqli.affected-rows">mysqli-&gt;affected_rows</varname></fieldsynopsis>
14
+
<para>&style.procedural;</para>
18
15
<methodsynopsis>
19
-
<type>int</type><methodname>mysqli_affected_rows</methodname>
20
-
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
16
+
<type class="union"><type>int</type><type>string</type></type><methodname>mysqli_affected_rows</methodname>
17
+
<methodparam><type>mysqli</type><parameter>mysql</parameter></methodparam>
21
18
</methodsynopsis>
22
19
<para>
23
20
Returns the number of rows affected by the last <literal>INSERT</literal>,
24
21
<literal>UPDATE</literal>, <literal>REPLACE</literal> or
25
22
<literal>DELETE</literal> query.
26
-
</para>
27
-
<para>
28
-
For SELECT statements <function>mysqli_affected_rows</function> works like
29
-
<function>mysqli_num_rows</function>.
23
+
Works like <function>mysqli_num_rows</function> for
24
+
<literal>SELECT</literal> statements.
30
25
</para>
31
26
</refsect1>
32
27
...
...
@@ -43,16 +38,18 @@
43
38
&reftitle.returnvalues;
44
39
<para>
45
40
An integer greater than zero indicates the number of rows affected or
46
-
retrieved.
47
-
Zero indicates that no records where updated for an UPDATE statement, no
48
-
rows matched the <literal>WHERE</literal> clause in the query or that no
49
-
query has yet been executed. -1 indicates that the query returned an
50
-
error.
41
+
retrieved. Zero indicates that no records were updated for an
42
+
<literal>UPDATE</literal> statement, no rows matched the
43
+
<literal>WHERE</literal> clause in the query or that no query has yet been
44
+
executed. <literal>-1</literal> indicates that the query returned an error or
45
+
that <function>mysqli_affected_rows</function> was called for an unbuffered
46
+
<literal>SELECT</literal> query.
51
47
</para>
52
48
<note>
53
49
<para>
54
-
If the number of affected rows is greater than maximal int value, the
55
-
number of affected rows will be returned as a string.
50
+
If the number of affected rows is greater than the maximum int value
51
+
(<constant>PHP_INT_MAX</constant>), the number of affected rows will be
52
+
returned as a string.
56
53
</para>
57
54
</note>
58
55
</refsect1>
...
...
@@ -60,17 +57,14 @@
60
57
<refsect1 role="examples">
61
58
&reftitle.examples;
62
59
<example>
63
-
<title>Object oriented style</title>
60
+
<title><varname>$mysqli-&gt;affected_rows</varname> example</title>
61
+
<para>&style.oop;</para>
64
62
<programlisting role="php">
65
63
<![CDATA[
66
64
<?php
67
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
68
65

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

75
69
/* Insert rows */
76
70
$mysqli->query("CREATE TABLE Language SELECT * from CountryLanguage");
...
...
@@ -90,28 +84,17 @@ printf("Affected rows (DELETE): %d\n", $mysqli->affected_rows);
90
84
$result = $mysqli->query("SELECT CountryCode FROM Language");
91
85
printf("Affected rows (SELECT): %d\n", $mysqli->affected_rows);
92
86

93
-
$result->close();
94
-

95
87
/* Delete table Language */
96
88
$mysqli->query("DROP TABLE Language");
97
-

98
-
/* close connection */
99
-
$mysqli->close();
100
-
?>
101
89
]]>
102
90
</programlisting>
103
-
</example>
104
-
<example>
105
-
<title>Procedural style</title>
91
+
<para>&style.procedural;</para>
106
92
<programlisting role="php">
107
93
<![CDATA[
108
94
<?php
109
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
110
95

111
-
if (!$link) {
112
-
printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
113
-
exit();
114
-
}
96
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
97
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
115
98

116
99
/* Insert rows */
117
100
mysqli_query($link, "CREATE TABLE Language SELECT * from CountryLanguage");
...
...
@@ -131,26 +114,20 @@ printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($link));
131
114
$result = mysqli_query($link, "SELECT CountryCode FROM Language");
132
115
printf("Affected rows (SELECT): %d\n", mysqli_affected_rows($link));
133
116

134
-
mysqli_free_result($result);
135
-

136
117
/* Delete table Language */
137
118
mysqli_query($link, "DROP TABLE Language");
138
-

139
-
/* close connection */
140
-
mysqli_close($link);
141
-
?>
142
119
]]>
143
120
</programlisting>
144
-
</example>
145
-
&example.outputs;
146
-
<screen>
121
+
&examples.outputs;
122
+
<screen>
147
123
<![CDATA[
148
124
Affected rows (INSERT): 984
149
125
Affected rows (UPDATE): 168
150
126
Affected rows (DELETE): 815
151
127
Affected rows (SELECT): 169
152
128
]]>
153
-
</screen>
129
+
</screen>
130
+
</example>
154
131
</refsect1>
155
132

156
133
<refsect1 role="seealso">
...
...
@@ -164,7 +141,6 @@ Affected rows (SELECT): 169
164
141
</refsect1>
165
142

166
143
</refentry>
167
-

168
144
<!-- Keep this comment at the end of the file
169
145
Local variables:
170
146
mode: sgml
171
147