2003-03-15 23:01:35 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-03-16 15:26:37 +00:00
|
|
|
<!-- $Revision: 1.15 $ -->
|
|
|
|
<!-- EN-Revision: 1.14 Maintainer: baoengb Status: ready -->
|
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>
|
2004-03-16 15:26:37 +00:00
|
|
|
<refpurpose>Obtiene el número de filas afectadas en una operación
|
|
|
|
de MySQL previa</refpurpose>
|
2004-01-28 23:18:42 +00:00
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Descripción</title>
|
|
|
|
<para>Estilo por procedimientos:</para>
|
2004-01-28 23:18:42 +00:00
|
|
|
<methodsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<type>mixto</type><methodname>mysqli_affected_rows</methodname>
|
|
|
|
<methodparam><type>objeto</type><parameter>identificador_de_enlace</parameter></methodparam>
|
2004-01-28 23:18:42 +00:00
|
|
|
</methodsynopsis>
|
2004-03-16 15:26:37 +00:00
|
|
|
<para>Estilo orientado a objetos (característica):</para>
|
2004-01-28 23:18:42 +00:00
|
|
|
<classsynopsis>
|
|
|
|
<ooclass><classname>mysqli</classname></ooclass>
|
2004-03-16 15:26:37 +00:00
|
|
|
<fieldsynopsis><type>mixto</type><varname>affected_rows</varname></fieldsynopsis>
|
2004-01-28 23:18:42 +00:00
|
|
|
</classsynopsis>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
<function>mysqli_affected_rows</function> Regresa el número de filas
|
|
|
|
afectadas por la última consulta INSERT, UPDATE, o DELETE asociada
|
|
|
|
con el <parameter>identificador_de_enlace</parameter> dado. Si la última
|
|
|
|
consulta fue invalida, esta función regresará -1.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Para sentencias SELECT <function>mysqli_affected_rows</function> trabaja
|
|
|
|
igual a <function>mysqli_num_rows</function>.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
La función <function>mysqli_affected_rows</function> s&oacoute;lo trabaja
|
|
|
|
con consultas que modifican o afectan una tabla. En caso de que necesite el
|
|
|
|
número de filas de una consulta SELECT, use la función
|
|
|
|
<function>mysqli_num_rows</function> en su lugar.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Valores Regresados</title>
|
2004-01-28 23:18:42 +00:00
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Un entero mayor a cero indica el número de filas afectadas u obtenidas.
|
|
|
|
Cero indica que no se actualizaron registros para una sentencia UPDATE, no hubo
|
|
|
|
coincidencias con la clausula WHERE en la consulta o que no se ha ejecutado
|
|
|
|
aún ninguna consulta. -1 indica que la consulta regreso un error.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Si el número de filas afectadas es mayor que el valor entero máximo,
|
|
|
|
entonces el número de filas afectadas será regresado como una cadena.
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
2004-02-19 16:27:40 +00:00
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Vea también</title>
|
2004-02-19 16:27:40 +00:00
|
|
|
<para>
|
|
|
|
<function>mysqli_num_rows</function>,
|
|
|
|
<function>mysqli_info</function>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2004-01-28 23:18:42 +00:00
|
|
|
<refsect1>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Ejemplos</title>
|
2004-02-25 21:59:16 +00:00
|
|
|
<example>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Estilo orientado a objetos</title>
|
2004-02-25 21:59:16 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2004-02-19 16:27:40 +00:00
|
|
|
<?php
|
2004-02-25 21:59:16 +00:00
|
|
|
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* check connection */
|
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-25 21:59:16 +00:00
|
|
|
/* Insert rows */
|
|
|
|
$mysqli->query("CREATE TABLE Language SELECT * from CountryLanguage");
|
|
|
|
printf("Affected rows (INSERT): %d\n", $mysqli->affected_rows);
|
|
|
|
|
|
|
|
$mysqli->query("ALTER TABLE Language ADD Status int default 0");
|
|
|
|
|
|
|
|
/* update rows */
|
|
|
|
$mysqli->query("UPDATE Language SET Status=1 WHERE Percentage > 50");
|
|
|
|
printf("Affected rows (UPDATE): %d\n", $mysqli->affected_rows);
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* delete rows */
|
|
|
|
$mysqli->query("DELETE FROM Language WHERE Percentage < 50");
|
|
|
|
printf("Affected rows (DELETE): %d\n", $mysqli->affected_rows);
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* select all rows */
|
|
|
|
$result = $mysqli->query("SELECT CountryCode FROM Language");
|
|
|
|
printf("Affected rows (SELECT): %d\n", $mysqli->affected_rows);
|
2003-08-22 12:08:49 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
$result->close();
|
|
|
|
|
|
|
|
/* Delete table Language */
|
|
|
|
$mysqli->query("DROP TABLE Language");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* close connection */
|
|
|
|
$mysqli->close();
|
|
|
|
?>
|
2004-02-25 21:59:16 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<example>
|
2004-03-16 15:26:37 +00:00
|
|
|
<title>Estilo por procedimientos</title>
|
2004-02-25 21:59:16 +00:00
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2004-02-19 16:27:40 +00:00
|
|
|
<?php
|
2004-02-25 21:59:16 +00:00
|
|
|
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
if (!$link) {
|
|
|
|
printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* Insert rows */
|
|
|
|
mysqli_query($link, "CREATE TABLE Language SELECT * from CountryLanguage");
|
|
|
|
printf("Affected rows (INSERT): %d\n", mysqli_affected_rows($link));
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
mysqli_query($link, "ALTER TABLE Language ADD Status int default 0");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-25 21:59:16 +00:00
|
|
|
/* update rows */
|
|
|
|
mysqli_query($link, "UPDATE Language SET Status=1 WHERE Percentage > 50");
|
|
|
|
printf("Affected rows (UPDATE): %d\n", mysqli_affected_rows($link));
|
|
|
|
|
|
|
|
/* delete rows */
|
|
|
|
mysqli_query($link, "DELETE FROM Language WHERE Percentage < 50");
|
|
|
|
printf("Affected rows (DELETE): %d\n", mysqli_affected_rows($link));
|
|
|
|
|
|
|
|
/* select all rows */
|
|
|
|
$result = mysqli_query($link, "SELECT CountryCode FROM Language");
|
|
|
|
printf("Affected rows (SELECT): %d\n", mysqli_affected_rows($link));
|
|
|
|
|
|
|
|
mysqli_free_result($result);
|
|
|
|
|
|
|
|
/* Delete table Language */
|
|
|
|
mysqli_query($link, "DROP TABLE Language");
|
2004-01-28 23:18:42 +00:00
|
|
|
|
2004-02-19 16:27:40 +00:00
|
|
|
/* close connection */
|
|
|
|
mysqli_close($link);
|
|
|
|
?>
|
2004-02-25 21:59:16 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
<para>
|
2004-03-16 15:26:37 +00:00
|
|
|
Los ejemplos anteriores producirán la siguiente salida:
|
2004-01-28 23:18:42 +00:00
|
|
|
</para>
|
2004-02-25 21:59:16 +00:00
|
|
|
<screen>
|
|
|
|
<![CDATA[
|
|
|
|
Affected rows (INSERT): 984
|
|
|
|
Affected rows (UPDATE): 168
|
|
|
|
Affected rows (DELETE): 815
|
|
|
|
Affected rows (SELECT): 169
|
|
|
|
]]>
|
|
|
|
</screen>
|
2004-01-28 23:18:42 +00:00
|
|
|
</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
|
|
|
|
-->
|