mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
192 lines
5.9 KiB
XML
192 lines
5.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- splitted from ./ja/functions/pgsql.xml, last change in rev 1.6 -->
|
|
<!-- EN-Revision: 39bb8a868935a56cfce438b0169e13c02c93211c Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi -->
|
|
<refentry xml:id="function.pg-fetch-object" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_fetch_object</refname>
|
|
<refpurpose>行をオブジェクトとして得る</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> は、取得した行のフィールド名に
|
|
対応するプロパティを有するオブジェクトを返します。オプションとして、
|
|
指定したクラスのコンストラクタにパラメータを渡してインスタンス化する
|
|
ことも可能です。
|
|
</para>
|
|
&database.fetch-null;
|
|
<para>
|
|
速度面では、この関数は <function>pg_fetch_array</function> と同じであり、
|
|
<function>pg_fetch_row</function> とほとんど同じ程度です
|
|
(違いはわずかです)。
|
|
</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>
|
|
取得する行番号。最初の行は 0 です。省略したり &null; を指定したりした場合は、
|
|
次の行を取得します。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>class</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
インスタンス化し、プロパティを設定して戻り値とするクラスの名前。
|
|
指定しない場合は <classname>stdClass</classname> オブジェクトが返されます。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>constructor_args</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>class</parameter> オブジェクトのコンストラクタに
|
|
渡すオプションの配列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
結果の各フィールドに対応する属性を持つ <type>object</type> を返します。
|
|
データベースの <literal>NULL</literal> 値は &null; として返します。
|
|
</para>
|
|
<para>
|
|
<parameter>row</parameter> が結果の行数より大きい場合・行が存在しない場合
|
|
、そしてそれ以外のエラーが発生した場合は &false; を返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
<parameter>constructor_args</parameter> が空ではないのに、
|
|
クラスにコンストラクタが存在しない場合、
|
|
<classname>ValueError</classname> がスローされます。
|
|
</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>
|
|
<parameter>constructor_args</parameter> が空ではないのに、
|
|
クラスにコンストラクタが存在しない場合、
|
|
<classname>ValueError</classname> がスローされるようになりました。
|
|
これより前のバージョンでは、<classname>Exception</classname> がスローされていました。
|
|
</entry>
|
|
</row>
|
|
&pgsql.changelog.result-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><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 "Failed connecting to postgres database $database\n";
|
|
exit;
|
|
}
|
|
|
|
$qu = pg_query($db_conn, "SELECT * FROM books ORDER BY author");
|
|
|
|
|
|
while ($data = pg_fetch_object($qu)) {
|
|
echo $data->author . " (";
|
|
echo $data->year . "): ";
|
|
echo $data->title . "<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
|
|
-->
|