mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 15:12:22 +01:00
201 lines
6.0 KiB
XML
201 lines
6.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- splitted from ./en/functions/pgsql.xml, last change in rev 1.2 -->
|
|
<!-- EN-Revision: c2eca73ef79ebe78cebb34053e41b565af504c4f Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: takagi -->
|
|
<refentry xml:id="function.pg-query" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>pg_query</refname>
|
|
<refpurpose>クエリを実行する</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>PgSql\Result</type><type>false</type></type><methodname>pg_query</methodname>
|
|
<methodparam choice="opt"><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>query</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>pg_query</function> は、指定したデータベース
|
|
<parameter>connection</parameter> 上で <parameter>query</parameter>
|
|
を実行します。
|
|
特別な理由がない限り、この関数よりも <function>pg_query_params</function> を使うほうがいいでしょう。
|
|
</para>
|
|
<para>
|
|
エラーが発生して &false; が返された場合、もし接続が正常なら
|
|
<function>pg_last_error</function> 関数を使用してエラーの詳細情報が
|
|
取得可能です。
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<simpara>
|
|
<parameter>connection</parameter>は省略可能ですが、それは推奨されません。
|
|
なぜならスクリプトのバグが発見しにくくなるためです。
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
この関数は、以前は <function>pg_exec</function> と呼ばれていました。
|
|
<function>pg_exec</function> は互換性確保のためにまだ使用可能ですが、
|
|
新しい名前を使用することが推奨されています。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>connection</parameter></term>
|
|
<listitem>
|
|
&pgsql.parameter.connection-with-unspecified-default;
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>query</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
実行する 1 つまたは複数の SQL 文。複数の文が関数に渡された場合は、
|
|
明示的に BEGIN/COMMIT コマンドを指定していない限りはそれらの文は
|
|
ひとつのトランザクションとして実行されます。しかし、1 回のコールで
|
|
複数のトランザクションを実行することは推奨されません。
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
ユーザーから受け取ったデータを文字列に直接組み込むのは危険で、<link linkend="security.database.sql-injection">SQL
|
|
インジェクション</link> の脆弱性を引き起こしがちです。クエリ文字列に直接埋め込むのではなく、
|
|
<function>pg_query_params</function> を使ってパラメータとして指定することを推奨します。
|
|
</para>
|
|
<para>
|
|
ユーザーから受け取ったデータをクエリ文字列に直接埋め込む場合は、
|
|
<link linkend="function.pg-escape-string">適切にエスケープ</link>
|
|
する必要があります。
|
|
</para>
|
|
</warning>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
成功した場合に
|
|
<classname>PgSql\Result</classname> クラスのインスタンスを返します。
|
|
&return.falseforfailure;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
&pgsql.changelog.return-result-object;
|
|
&pgsql.changelog.connection-object;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>pg_query</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
if (!$conn) {
|
|
echo "An error occurred.\n";
|
|
exit;
|
|
}
|
|
|
|
$result = pg_query($conn, "SELECT author, email FROM authors");
|
|
if (!$result) {
|
|
echo "An error occurred.\n";
|
|
exit;
|
|
}
|
|
|
|
while ($row = pg_fetch_row($result)) {
|
|
echo "Author: $row[0] E-mail: $row[1]";
|
|
echo "<br />\n";
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>pg_query</function> で複数の文を使用する例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$conn = pg_pconnect("dbname=publisher");
|
|
|
|
// これらの文がひとつのトランザクションとして実行されます
|
|
|
|
$query = "UPDATE authors SET author=UPPER(author) WHERE id=1;";
|
|
$query .= "UPDATE authors SET author=LOWER(author) WHERE id=2;";
|
|
$query .= "UPDATE authors SET author=NULL WHERE id=3;";
|
|
|
|
pg_query($conn, $query);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pg_connect</function></member>
|
|
<member><function>pg_pconnect</function></member>
|
|
<member><function>pg_fetch_array</function></member>
|
|
<member><function>pg_fetch_object</function></member>
|
|
<member><function>pg_num_rows</function></member>
|
|
<member><function>pg_affected_rows</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
|
|
-->
|