reference/mysqli/mysqli_result/num-rows.xml
181e9c5572ed04ed712b8d7f858f61a94647c6ac
...
...
@@ -4,7 +4,7 @@
4
4
<refnamediv>
5
5
<refname>mysqli_result::$num_rows</refname>
6
6
<refname>mysqli_num_rows</refname>
7
-
<refpurpose>Gets the number of rows in a result</refpurpose>
7
+
<refpurpose>Gets the number of rows in the result set</refpurpose>
8
8
</refnamediv>
9
9

10
10
<refsect1 role="description">
...
...
@@ -22,9 +22,8 @@
22
22
<para>
23
23
The behaviour of <function>mysqli_num_rows</function> depends on whether
24
24
buffered or unbuffered result sets are being used.
25
-
For unbuffered result sets, <function>mysqli_num_rows</function>
26
-
will not return the correct number of rows until all the rows in the result
27
-
have been retrieved.
25
+
This function returns <literal>0</literal> for unbuffered result sets unless
26
+
all rows have been fetched from the server.
28
27
</para>
29
28
</refsect1>
30
29

...
...
@@ -40,14 +39,11 @@
40
39
<refsect1 role="returnvalues">
41
40
&reftitle.returnvalues;
42
41
<para>
43
-
Returns number of rows in the result set.
42
+
An &integer; representing the number of fetched rows.
43
+
Returns <literal>0</literal> in unbuffered mode unless all rows have been
44
+
fetched from the server.
44
45
</para>
45
-
<note>
46
-
<para>
47
-
If the number of rows is greater than <constant>PHP_INT_MAX</constant>, the number
48
-
will be returned as a string.
49
-
</para>
50
-
</note>
46
+
&mysqli.integer.overflow.as.string.note;
51
47
</refsect1>
52
48

53
49
<refsect1 role="examples">
...
...
@@ -57,28 +53,16 @@
57
53
<programlisting role="php">
58
54
<![CDATA[
59
55
<?php
60
-
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
61
56

62
-
/* check connection */
63
-
if (mysqli_connect_errno()) {
64
-
printf("Connect failed: %s\n", mysqli_connect_error());
65
-
exit();
66
-
}
67
-

68
-
if ($result = $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name")) {
69
-

70
-
/* determine number of rows result set */
71
-
$row_cnt = $result->num_rows;
57
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
58
+
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
72
59

73
-
printf("Result set has %d rows.\n", $row_cnt);
60
+
$result = $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name");
74
61

75
-
/* close result set */
76
-
$result->close();
77
-
}
62
+
/* Get the number of rows in the result set */
63
+
$row_cnt = $result->num_rows;
78
64

79
-
/* close connection */
80
-
$mysqli->close();
81
-
?>
65
+
printf("Result set has %d rows.\n", $row_cnt);
82
66
]]>
83
67
</programlisting>
84
68
</example>
...
...
@@ -87,28 +71,16 @@ $mysqli->close();
87
71
<programlisting role="php">
88
72
<![CDATA[
89
73
<?php
90
-
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
91
74

92
-
/* check connection */
93
-
if (mysqli_connect_errno()) {
94
-
printf("Connect failed: %s\n", mysqli_connect_error());
95
-
exit();
96
-
}
97
-

98
-
if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {
99
-

100
-
/* determine number of rows result set */
101
-
$row_cnt = mysqli_num_rows($result);
75
+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
76
+
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
102
77

103
-
printf("Result set has %d rows.\n", $row_cnt);
78
+
$result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name");
104
79

105
-
/* close result set */
106
-
mysqli_free_result($result);
107
-
}
80
+
/* Get the number of rows in the result set */
81
+
$row_cnt = mysqli_num_rows($result);
108
82

109
-
/* close connection */
110
-
mysqli_close($link);
111
-
?>
83
+
printf("Result set has %d rows.\n", $row_cnt);
112
84
]]>
113
85
</programlisting>
114
86
&examples.outputs;
...
...
@@ -120,6 +92,17 @@ Result set has 239 rows.
120
92
</example>
121
93
</refsect1>
122
94

95
+
<refsect1 role="notes">
96
+
&reftitle.notes;
97
+
<note>
98
+
<para>
99
+
In contrast to the <function>mysqli_stmt_num_rows</function> function,
100
+
this function doesn't have object-oriented method variant.
101
+
In the object-oriented style, use the getter property.
102
+
</para>
103
+
</note>
104
+
</refsect1>
105
+

123
106
<refsect1 role="seealso">
124
107
&reftitle.seealso;
125
108
<para>
...
...
@@ -128,6 +111,7 @@ Result set has 239 rows.
128
111
<member><function>mysqli_store_result</function></member>
129
112
<member><function>mysqli_use_result</function></member>
130
113
<member><function>mysqli_query</function></member>
114
+
<member><function>mysqli_stmt_num_rows</function></member>
131
115
</simplelist>
132
116
</para>
133
117
</refsect1>
134
118