mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 15:32:36 +01:00
176 lines
5.5 KiB
XML
176 lines
5.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 39bb8a868935a56cfce438b0169e13c02c93211c Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.pg-fetch-object" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_fetch_object</refname>
|
|
<refpurpose>
|
|
Lee una fila de resultado PostgreSQL en un objeto
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>object</type><type>false</type></type><methodname>pg_fetch_object</methodname>
|
|
<methodparam><type>PgSql\Result</type><parameter>result</parameter></methodparam>
|
|
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>row</parameter><initializer>&null;</initializer></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>class</parameter><initializer>"stdClass"</initializer></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>constructor_args</parameter><initializer>[]</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_fetch_object</function> devuelve un objeto con sus propiedades que corresponden a los nombres de los campos de la fila. La función puede instanciar opcionalmente un objeto de una clase específica y pasar los argumentos al constructor de dicha clase.
|
|
</para>
|
|
&database.fetch-null;
|
|
<para>
|
|
En cuanto a velocidad, la función es idéntica a <function>pg_fetch_array</function> y es casi tan rápida como <function>pg_fetch_row</function> (la diferencia es insignificante).
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>result</parameter></term>
|
|
<listitem>
|
|
&pgsql.parameter.result;
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>row</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Número de la fila a recuperar. Las filas se numeran comenzando por 0. Si el argumento se omite o es &null;, se recupera la siguiente fila.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>class</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El nombre de la clase a instanciar, fija las propiedades de esta y sus valores de retorno. Si no se especifica nada, se devuelve un objeto de tipo <classname>stdClass</classname>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>constructor_args</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Parámetro opcional de tipo <type>array</type> para pasar argumentos al constructor de la clase <parameter>class</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Un objeto de tipo <type>object</type> con los atributos para cada campo en el conjunto de resultados. Los valores &null; de la base de datos se devuelven como &null;.
|
|
</para>
|
|
<para>
|
|
&false; se devuelve si <parameter>row</parameter> excede el número de filas en el conjunto de resultados, no hay más filas disponibles o cualquier otro error.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Se lanza una <classname>ValueError</classname> cuando el argumento <parameter>constructor_args</parameter> no está vacío y la clase no tiene constructor.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
Ahora lanza una excepción <classname>ValueError</classname> cuando el argumento <parameter>constructor_args</parameter> no está vacío y la clase no tiene constructor; anteriormente, se lanzaba una excepción <classname>Exception</classname>.
|
|
</entry>
|
|
</row>
|
|
&pgsql.changelog.result-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>pg_fetch_object</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$database = 'store';
|
|
|
|
$db_conn = pg_connect("host=localhost port=5432 dbname=$database");
|
|
if (!$db_conn) {
|
|
echo "La conexión a la base $database ha fallado\n";
|
|
exit;
|
|
}
|
|
|
|
$qu = pg_query($db_conn, "SELECT * FROM libros ORDER BY autor");
|
|
|
|
while ($data = pg_fetch_object($qu)) {
|
|
echo $data->autor . " (";
|
|
echo $data->anio . "): ";
|
|
echo $data->titulo . "<br />";
|
|
}
|
|
|
|
pg_free_result($qu);
|
|
pg_close($db_conn);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_query</function></member>
|
|
<member><function>pg_fetch_array</function></member>
|
|
<member><function>pg_fetch_assoc</function></member>
|
|
<member><function>pg_fetch_row</function></member>
|
|
<member><function>pg_fetch_result</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:"~/.phpdoc/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
|
|
-->
|