mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
minor fixed. Added and corrected samples
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@138481 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
268c48bbec
commit
0ee6c80146
1 changed files with 65 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.7 $ -->
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<refentry id="function.mysqli-affected-rows">
|
||||
<refnamediv>
|
||||
<refname>mysqli_affected_rows</refname>
|
||||
|
@ -9,7 +9,7 @@
|
|||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>mixed</type><methodname>mysqli_affected_rows</methodname>
|
||||
<methodparam><type>resource</type><parameter>link</parameter></methodparam>
|
||||
<methodparam><type>object</type><parameter>link</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
<function>mysqli_affected_rows</function> returns the number of rows affected by the last
|
||||
|
@ -30,52 +30,96 @@
|
|||
<para>
|
||||
<example>
|
||||
<title>Delete-Query</title>
|
||||
<para>Procedural style:</para>
|
||||
<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");
|
||||
$link = mysqli_connect("localhost", "mysql_user", "mysql_password", "mydb") or
|
||||
die("Could not connect: " . mysqli_connect_error());
|
||||
|
||||
/* 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());
|
||||
mysqli_query($link, "DELETE FROM mytable WHERE id < 10");
|
||||
printf ("Records deleted: %2d\n", mysqli_affected_rows($link));
|
||||
|
||||
/* 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());
|
||||
mysqli_query($link, "DELETE FROM mytable");
|
||||
printf ("Records deleted: %2d\n", mysqli_affected_rows($link));
|
||||
|
||||
/* close connection */
|
||||
mysqli_close($link);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>Object oriented style:</para>
|
||||
<programlisting>
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* connect to database */
|
||||
$mysql = mysqli_connect("localhost", "mysql_user", "mysql_password", "mydb") or
|
||||
die("Could not connect: " . mysqli_connect_error());
|
||||
|
||||
/* this should return the correct numbers of deleted records */
|
||||
$mysql->query("DELETE FROM mytable WHERE id < 10");
|
||||
printf ("Records deleted: %2d\n", $mysql->affected_rows());
|
||||
|
||||
/* without a where clause in a delete statement, it should return 0 */
|
||||
$mysql->query("DELETE FROM mytable");
|
||||
printf ("Records deleted: %2d\n", $mysql->affected_rows());
|
||||
|
||||
/* close connection */
|
||||
$mysql->close();
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example would produce the following output:
|
||||
The above examples would produce the following output:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Records deleted: 10
|
||||
Records deleted: 0
|
||||
Records deleted: 0
|
||||
]]>
|
||||
</screen>
|
||||
</para>
|
||||
</example>
|
||||
<example>
|
||||
<title>Update-Query</title>
|
||||
<para>Procedural style:</para>
|
||||
<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");
|
||||
$link = mysqli_connect("localhost", "mysql_user", "mysql_password", "mydb") or
|
||||
die("Could not connect: " . mysqli_connect_error());
|
||||
|
||||
/* Update records */
|
||||
mysqli_query("UPDATE mytable SET used=1 WHERE id < 10");
|
||||
printf ("Updated records: %d\n", mysqli_affected_rows());
|
||||
mysqli_query($link, "UPDATE mytable SET used=1 WHERE id < 10");
|
||||
printf ("Updated records: %d\n", mysqli_affected_rows($link));
|
||||
|
||||
/* close connection */
|
||||
mysqli_close($link);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>Object oriented style:</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* connect to database */
|
||||
$mysql = mysqli_connect("localhost", "mysql_user", "mysql_password", "mydb") or
|
||||
die("Could not connect: " . mysqli_connect_error());
|
||||
|
||||
/* Update records */
|
||||
$mysql->query("UPDATE mytable SET used=1 WHERE id < 10");
|
||||
printf ("Updated records: %d\n", $mysql->affected_rows($link));
|
||||
|
||||
/* close connection */
|
||||
mysql->close($link);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
The above example would produce the following output:
|
||||
The above examples would produce the following output:
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Updated Records: 10
|
||||
|
@ -84,6 +128,10 @@ Updated Records: 10
|
|||
</para>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
See also: <function>mysqli_num_rows</function>,
|
||||
<function>mysqli_info</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue