php-doc-en/reference/mysqli/functions/mysqli-affected-rows.xml
Georg Richter 8190ee59a5 little docu update
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@150059 c90b9560-bf6c-de11-be94-00142212c4b1
2004-01-28 23:18:42 +00:00

153 lines
5.3 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.12 $ -->
<refentry id="function.mysqli-affected-rows">
<refnamediv>
<refname>mysqli_affected_rows</refname>
<refname>mysqli->affected_rows</refname>
<refpurpose>Gets the number of affected rows in a previous MySQL operation</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>mixed</type><methodname>mysqli_affected_rows</methodname>
<methodparam><type>object</type><parameter>link</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (property):</para>
<classsynopsis>
<ooclass><classname>mysqli</classname></ooclass>
<fieldsynopsis><type>mixed</type><varname>affected_rows</varname></fieldsynopsis>
</classsynopsis>
<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>
For SELECT statements <function>mysqli_affected_rows</function> works like
<function>mysqli_num_rows</function>.
</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>
</refsect1>
<refsect1>
<title>Return Values</title>
<para>
An integer greater than zero indicates the number of rows affected or retrieved.
Zero indicates that no records where updated for an UPDATE statement, no rows matched
the WHERE clause in the query or that no query has yet been executed.
-1 indicates that the query returned an error.
</para>
<note>
<para>
If the number of affected rows is greater than maximal int value, the number of affected rows
will be returned as a string.
</para>
</note>
</refsect1>
<refsect1>
<title>Example</title>
<para>
<example>
<title>Example for affected rows</title>
<programlisting role="php">
<![CDATA[
<?php
/*
+-----------------------------------------------------------+
| file: mysqli_affected_rows.php |
+-----------------------------------------------------------+
| modifies some datasets and returns number of affected |
| rows |
+-----------------------------------------------------------+
*/
/* ---- Procedural style ---- */
$link = mysqli_connect("localhost", "my_user", "my_password", "test")
or die("Can't connect to MySQL server on localhost");
/* create table and insert some data */
mysqli_query($link, "DROP TABLE IF EXISTS affected_rows");
mysqli_query($link, "CREATE TABLE affected_rows (a int)");
mysqli_query($link, "INSERT INTO affected_rows VALUES (1),(2),(3),(4)");
/* update values and retrieve number of affected rows */
mysqli_query($link, "UPDATE affected_rows SET a=5 WHERE a=1");
printf("Affected rows (update): %d\n", mysqli_affected_rows($link));
/* delete rows and retrieve number of affected_rows */
mysqli_query($link, "DELETE FROM affected_rows WHERE a < 4");
printf("Affected rows (delete): %d\n", mysqli_affected_rows($link));
/* select all rows and retrieve number of affected_rows */
mysqli_query($link, "SELECT a FROM affected_rows");
printf("Affected rows (select): %d\n", mysqli_affected_rows($link));
mysqli_close($link);
/* ---- Object oriented style ----*/
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* create table and insert some data */
$mysqli->query("DROP TABLE IF EXISTS affected_rows");
$mysqli->query("CREATE TABLE affected_rows (a int)");
$mysqli->query("INSERT INTO affected_rows VALUES (1),(2),(3),(4)");
/* update values and retrieve number of affected rows */
$mysqli->query("UPDATE affected_rows SET a=5 WHERE a=1");
printf("Affected rows (update): %d\n", $mysqli->affected_rows);
/* delete rows and retrieve number of affected_rows */
$mysqli->query("DELETE FROM affected_rows WHERE a < 4");
printf("Affected rows (delete): %d\n", $mysqli->affected_rows);
/* select all rows and retrieve number of affected_rows */
$mysqli->query("SELECT a FROM affected_rows");
printf("Affected rows (select): %d\n", $mysqli->affected_rows);
$mysqli->close();
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<function>mysqli_num_rows</function>,
<function>mysqli_info</function>.
</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
-->