<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.11 $ --> <refentry id="function.mysqli-stmt-affected-rows"> <refnamediv> <refname>mysqli_stmt_affected_rows</refname> <refname>mysqli_stmt->affected_rows</refname> <refpurpose>Returns the total number of rows changed, deleted, or inserted by the last executed statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <para>Procedural style :</para> <methodsynopsis> <type>int</type><methodname>mysqli_stmt_affected_rows</methodname> <methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam> </methodsynopsis> <para>Object oriented style (property):</para> <classsynopsis> <ooclass><classname>mysqli_stmt</classname></ooclass> <fieldsynopsis><type>int</type><varname>affected_rows</varname></fieldsynopsis> </classsynopsis> <para> Returns the number of rows affected by <literal>INSERT</literal>, <literal>UPDATE</literal>, or <literal>DELETE</literal> query. </para> <para> This function only works with queries which update a table. In order to get the number of rows from a SELECT query, use <function>mysqli_stmt_num_rows</function> instead. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> &mysqli.stmt.description; </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE/DELETE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query has returned an error. </para> <note> <para> If the number of affected rows is greater than maximal PHP int value, the number of affected rows will be returned as a string value. </para> </note> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example> <title>Object oriented style</title> <programlisting role="php"> <![CDATA[ <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* create temp table */ $mysqli->query("CREATE TEMPORARY TABLE myCountry LIKE Country"); $query = "INSERT INTO myCountry SELECT * FROM Country WHERE Code LIKE ?"; /* prepare statement */ if ($stmt = $mysqli->prepare($query)) { /* Bind variable for placeholder */ $code = 'A%'; $stmt->bind_param("s", $code); /* execute statement */ $stmt->execute(); printf("rows inserted: %d\n", $stmt->affected_rows); /* close statement */ $stmt->close(); } /* close connection */ $mysqli->close(); ?> ]]> </programlisting> </example> <example> <title>Procedural style</title> <programlisting role="php"> <![CDATA[ <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } /* create temp table */ mysqli_query($link, "CREATE TEMPORARY TABLE myCountry LIKE Country"); $query = "INSERT INTO myCountry SELECT * FROM Country WHERE Code LIKE ?"; /* prepare statement */ if ($stmt = mysqli_prepare($link, $query)) { /* Bind variable for placeholder */ $code = 'A%'; mysqli_stmt_bind_param($stmt, "s", $code); /* execute statement */ mysqli_stmt_execute($stmt); printf("rows inserted: %d\n", mysqli_stmt_affected_rows($stmt)); /* close statement */ mysqli_stmt_close($stmt); } /* close connection */ mysqli_close($link); ?> ]]> </programlisting> </example> &example.outputs; <screen> <![CDATA[ rows inserted: 17 ]]> </screen> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><function>mysqli_stmt_num_rows</function></member> <member><function>mysqli_prepare</function></member> </simplelist> </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 -->