2003-03-15 23:01:35 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-02-19 16:27:40 +00:00
|
|
|
<!-- $Revision: 1.13 $ -->
|
2003-03-15 23:01:35 +00:00
|
|
|
<refentry id="function.mysqli-affected-rows">
|
2004-01-28 23:18:42 +00:00
|
|
|
<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>
|
2004-02-19 16:27:40 +00:00
|
|
|
<refsect1>
|
|
|
|
<title>See also</title>
|
|
|
|
<para>
|
|
|
|
<function>mysqli_num_rows</function>,
|
|
|
|
<function>mysqli_info</function>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2004-01-28 23:18:42 +00:00
|
|
|
<refsect1>
|
|
|
|
<title>Example</title>
|
|
|
|
<para>
|
|
|
|
<example>
|
2004-02-19 16:27:40 +00:00
|
|
|
<title>Object oriented style</title>
|
2004-01-28 23:18:42 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2004-02-19 16:27:40 +00:00
|
|
|
<?php
|
|
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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)");
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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);
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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);
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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);
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* close connection */
|
|
|
|
$mysqli->close();
|
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<example>
|
|
|
|
<title>Procedural style</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "test")
|
|
|
|
or die("Can't connect to MySQL server on localhost");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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)");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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));
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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));
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* 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));
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* close connection */
|
|
|
|
mysqli_close($link);
|
|
|
|
?>
|
2004-01-28 23:18:42 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2003-03-15 23:01:35 +00:00
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
-->
|