php-doc-en/reference/mysqli/functions/mysqli-affected-rows.xml
Georg Richter bed14006a3 removed parenthesis
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@131038 c90b9560-bf6c-de11-be94-00142212c4b1
2003-06-11 13:00:48 +00:00

109 lines
3.2 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<refentry id="function.mysqli-affected-rows">
<refnamediv>
<refname>mysqli_affected_rows</refname>
<refpurpose>Gets the number of affected rows in a previous MySQL operation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>mixed</type><methodname>mysqli_affected_rows</methodname>
<methodparam><type>resource</type><parameter>link</parameter></methodparam>
</methodsynopsis>
<para>
<function>mysqli_affected_rows</function> returns the number of rows affected by the last
INSERT, UPDATE, or DELETE query associated with the provided <parameter>link</parameter>
parameter. If the last query was invalid, this function will return -1.
</para>
<note>
<para>
When deleting the entire contents of a table (i.e. 'DELETE FROM foo'), this function will
not return the number of rows that were actually deleted.
</para>
</note>
<para>
The <function>mysqli_affected_rows</function> function only works with queries which modify
a table. In order to return the number of rows from a SELECT query, use the
<function>mysqli_num_rows</function> function instead.
</para>
<para>
<example>
<title>Delete-Query</title>
<programlisting role="php">
<![CDATA[
<?php
/* connect to database */
mysqli_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysqli_error());
mysqli_select_db("mydb");
/* this should return the correct numbers of deleted records */
mysqli_query("DELETE FROM mytable WHERE id < 10");
printf ("Records deleted: %d\n", mysqli_affected_rows());
/* without a where clause in a delete statement, it should return 0 */
mysqli_query("DELETE FROM mytable");
printf ("Records deleted: %d\n", mysqli_affected_rows());
?>
]]>
</programlisting>
<para>
The above example would produce the following output:
<screen>
<![CDATA[
Records deleted: 10
Records deleted: 0
]]>
</screen>
</para>
</example>
<example>
<title>Update-Query</title>
<programlisting role="php">
<![CDATA[
<?php
/* connect to database */
mysqli_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysqli_error());
mysqli_select_db("mydb");
/* Update records */
mysqli_query("UPDATE mytable SET used=1 WHERE id < 10");
printf ("Updated records: %d\n", mysqli_affected_rows());
?>
]]>
</programlisting>
<para>
The above example would produce the following output:
<screen>
<![CDATA[
Updated Records: 10
]]>
</screen>
</para>
</example>
</para>
</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
-->