php-doc-en/reference/mysqli/functions/mysqli-num-rows.xml
Georg Richter 0768abafe7 added more samples
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@152467 c90b9560-bf6c-de11-be94-00142212c4b1
2004-02-26 14:48:54 +00:00

146 lines
3.7 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.5 $ -->
<refentry id="function.mysqli-num-rows">
<refnamediv>
<refname>mysqli_num_rows</refname>
<refpurpose>
Gets the number of rows in a result
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>mixed</type><methodname>mysqli_num_rows</methodname>
<methodparam><type>object</type><parameter>result</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (property):</para>
<classsynopsis>
<ooclass><classname>mysqli</classname></ooclass>
<fieldsynopsis><type>mixed</type><varname>num_rows</varname></fieldsynopsis>
</classsynopsis>
<para>
Returns the number of rows in the result set.
</para>
<para>
The use of <function>mysqli_num_rows</function> depends on whether you use
buffered or unbuffered result sets.
In case you use unbuffered resultsets <function>mysqli_num_rows</function>
will not correct the correct number of rows until all the rows in the result
have been retrieved.
</para>
</refsect1>
<refsect1>
&reftitle.returnvalues;
<para>
Returns number of rows in the result set.
</para>
<note>
<para>
If the number of rows is greater than maximal int value, the number
will be returned as a string.
</para>
</note>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>mysqli_affected_rows</function>
<function>mysqli_store_result</function>
<function>mysqli_use_result</function>
<function>mysqli_query</function>
</para>
</refsect1>
<refsect1>
<title>Example</title>
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
/* close result set */
$result->close();
}
/* close connection */
$mysqli->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Procedural style</title>
<programlisting role="php">
<![CDATA[
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($result);
printf("Result set has %d rows.\n", $row_cnt);
/* close result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
</example>
<para>
The above examples would produce the following output:
</para>
<screen>
<![CDATA[
Result set has 239 rows.
]]>
</screen>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->