Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 1670

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>mysql_affected_rows</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="MySQL Functions"
HREF="ref.mysql.html"><LINK
REL="PREVIOUS"
TITLE="MySQL Functions"
HREF="ref.mysql.html"><LINK
REL="NEXT"
TITLE="mysql_change_user"
HREF="function.mysql-change-user.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="ref.mysql.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.mysql-change-user.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.mysql-affected-rows"
></A
>mysql_affected_rows</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN58176"
></A
><P
>    (PHP 3, PHP 4 )</P
>mysql_affected_rows&nbsp;--&nbsp;Get number of affected rows in previous MySQL
     operation</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN58179"
></A
><H2
>Description</H2
>int <B
CLASS="methodname"
>mysql_affected_rows</B
> ( [resource link_identifier])<BR
></BR
><P
>&#13;     <B
CLASS="function"
>mysql_affected_rows()</B
> returns the number
     of rows affected by the last INSERT, UPDATE or DELETE query
     associated with <TT
CLASS="parameter"
><I
>link_identifier</I
></TT
>.  If the
     link identifier isn't specified, the last link opened by
     <A
HREF="function.mysql-connect.html"
><B
CLASS="function"
>mysql_connect()</B
></A
> is assumed.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      If you are using transactions, you need to call
      <B
CLASS="function"
>mysql_affected_rows()</B
> after your INSERT,
      UPDATE, or DELETE query, not after the commit.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     If the last query was a DELETE query with no WHERE clause, all
     of the records will have been deleted from the table but this
     function will return zero.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      When using UPDATE, MySQL will not update columns where the new
      value is the same as the old value.  This creates the possiblity
      that <B
CLASS="function"
>mysql_affected_rows()</B
> may not actually
      equal the number of rows matched, only the number of rows that
      were literally affected by the query.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     <B
CLASS="function"
>mysql_affected_rows()</B
> does not work with
     SELECT statements; only on statements which modify records. To
     retrieve the number of rows returned by a SELECT, use
     <A
HREF="function.mysql-num-rows.html"
><B
CLASS="function"
>mysql_num_rows()</B
></A
>.
    </P
><P
>&#13;     If the last query failed, this function will return -1.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN58202"
></A
><P
><B
>Example 1. Delete-Query</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    /* connect to database */
    mysql_pconnect("localhost", "mysql_user", "mysql_password") or
        die("Could not connect: " . mysql_error());

    /* this should return the correct numbers of deleted records */
    mysql_query("DELETE FROM mytable WHERE id &#60; 10");
    printf ("Records deleted: %d\n", mysql_affected_rows());

    /* without a where clause in a delete statement, it should return 0 */
    mysql_query("DELETE FROM mytable");
    printf ("Records deleted: %d\n", mysql_affected_rows());
?&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13;      The above example would produce the following output:
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Records deleted: 10
Records deleted: 0</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
>
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN58207"
></A
><P
><B
>Example 2. Update-Query</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
    /* connect to database */
    mysql_pconnect("localhost", "mysql_user", "mysql_password") or
        die("Could not connect: " . mysql_error());

    /* Update records */
    mysql_query("UPDATE mytable SET used=1 WHERE id &#60; 10");
    printf ("Updated records: %d\n", mysql_affected_rows());
mysql_query("COMMIT");
?&#62;</PRE
></TD
></TR
></TABLE
><P
>&#13;       The above example would produce the following output:
       <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Updated Records: 10</PRE
></TD
></TR
></TABLE
>
      </P
></DIV
></TD
></TR
></TABLE
> 
    </P
><P
>&#13;     See also: <A
HREF="function.mysql-num-rows.html"
><B
CLASS="function"
>mysql_num_rows()</B
></A
>,
               <A
HREF="function.mysql-info.html"
><B
CLASS="function"
>mysql_info()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="ref.mysql.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.mysql-change-user.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>MySQL Functions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.mysql.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>mysql_change_user</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>