mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 15:12:22 +01:00
218 lines
7.9 KiB
XML
218 lines
7.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 18aa2012f6fa1e5b09733147e02911d16e06d4a1 Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi,mumumu -->
|
|
<refentry xml:id="function.pg-select" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_select</refname>
|
|
<refpurpose>
|
|
レコードを選択する
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>string</type><type>false</type></type><methodname>pg_select</methodname>
|
|
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>table_name</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>conditions</parameter><initializer>[]</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>PGSQL_DML_EXEC</constant></initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>PGSQL_ASSOC</constant></initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_select</function> は、<literal>field=>value</literal>
|
|
形式の <literal>conditions</literal> で指定したレコードを選択します。
|
|
クエリに成功した場合、<literal>conditions</literal> で指定した条件に
|
|
マッチする全てのレコードとフィールドを含む配列が返されます。
|
|
</para>
|
|
<para>
|
|
<literal>flags</literal> が指定された場合、
|
|
指定したフラグとともに <function>pg_convert</function> が
|
|
<literal>conditions</literal> に適用されます。
|
|
</para>
|
|
<para>
|
|
<parameter>mode</parameter> が指定された場合、
|
|
戻り値は <constant>PGSQL_NUM</constant> の場合配列、
|
|
<constant>PGSQL_ASSOC</constant> の場合連想配列(これがデフォルトです)、
|
|
<constant>PGSQL_BOTH</constant> の場合数値と連想配列のインデックスが両方含まれた配列になります。
|
|
</para>
|
|
<para>
|
|
<function>pg_update</function> は生の値を渡します。
|
|
値はエスケープするか、PGSQL_DML_ESCAPE オプションを指定しなければいけません。
|
|
PGSQL_DML_ESCAPE はパラメータや識別子をクォートし、エスケープします。
|
|
よって、テーブル/カラム名は大文字小文字を区別します。
|
|
</para>
|
|
<para>
|
|
エスケープやプリペアドクエリであっても、
|
|
LIKE, JSON, Array, Regex などのクエリを守れない可能性があることに注意してください。
|
|
これらのパラメータはコンテクストに応じて処理されるべきです。
|
|
たとえば、値をエスケープ/検証する処理を行うことなどです。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>connection</parameter></term>
|
|
<listitem>
|
|
&pgsql.parameter.connection;
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>table_name</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
行を選択するテーブルの名前。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>conditions</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
テーブル <parameter>table_name</parameter>
|
|
のフィールド名をキーに、
|
|
取得対象となる行にマッチするデータを値にもつ配列。
|
|
PHP 8.4.0 以降は、空の配列を指定した場合には条件は適用されなくなっています。それより前のバージョンでは、<parameter>conditions</parameter> が空の場合は、関数そのものが失敗していました。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<constant>PGSQL_CONV_FORCE_NULL</constant>,
|
|
<constant>PGSQL_DML_NO_CONV</constant>,
|
|
<constant>PGSQL_DML_ESCAPE</constant>,
|
|
<constant>PGSQL_DML_EXEC</constant>,
|
|
<constant>PGSQL_DML_ASYNC</constant>,
|
|
<constant>PGSQL_DML_STRING</constant> の組み合わせ。
|
|
<parameter>flags</parameter> の一部に
|
|
<constant>PGSQL_DML_STRING</constant>
|
|
が含まれていた場合、クエリ文字列が返されます。
|
|
<constant>PGSQL_DML_NO_CONV</constant> あるいは
|
|
<constant>PGSQL_DML_ESCAPE</constant> が設定されている場合は、
|
|
内部的に <function>pg_convert</function> を呼び出しません。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>mode</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<constant>PGSQL_ASSOC</constant>,
|
|
<constant>PGSQL_NUM</constant>,
|
|
<constant>PGSQL_BOTH</constant> の組み合わせ。
|
|
<constant>PGSQL_ASSOC</constant> が設定されている場合、
|
|
戻り値は連想配列になります。
|
|
<constant>PGSQL_NUM</constant> が設定されている場合、
|
|
戻り値は配列になります。
|
|
<constant>PGSQL_BOTH</constant> が設定されている場合、
|
|
戻り値は数値と連想配列のインデックスが両方含まれた配列になります。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<parameter>flags</parameter> に
|
|
<constant>PGSQL_DML_STRING</constant> が渡された場合は文字列を返します。
|
|
それ以外の場合は、成功時に配列を返します。
|
|
&return.falseforfailure;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.4.0</entry>
|
|
<entry>
|
|
<parameter>conditions</parameter> は、オプションになりました。
|
|
</entry>
|
|
</row>
|
|
&pgsql.changelog.connection-object;
|
|
<row>
|
|
<entry>7.1.0</entry>
|
|
<entry>
|
|
<parameter>mode</parameter> パラメータが追加されました。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>pg_select</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$db = pg_connect('dbname=foo');
|
|
// これは少しだけ安全です。なぜなら、全ての値がエスケープされるからです。
|
|
// しかし、PostgreSQL は JSON/Array をサポートしています。これらの型に
|
|
// ついてはエスケープされたクエリや、プリペアドクエリでも安全ではありません。
|
|
$rec = pg_select($db, 'post_log', $_POST);
|
|
if ($rec) {
|
|
echo "選択されたレコード:\n";
|
|
var_dump($rec);
|
|
} else {
|
|
echo "ユーザーが誤った入力を送信しました。\n";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_convert</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
|
|
-->
|