mirror of
https://github.com/php/doc-ja.git
synced 2026-03-30 02:52:08 +02:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@193845 c90b9560-bf6c-de11-be94-00142212c4b1
346 lines
13 KiB
XML
346 lines
13 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- $Revision: 1.9 $ -->
|
||
<!-- EN-Revision: 1.25 Maintainer: hirokawa Status: ready -->
|
||
<!-- CREDITS: takagi -->
|
||
<reference id="ref.pgsql">
|
||
<title>PostgreSQL 関数</title>
|
||
<titleabbrev>PostgreSQL</titleabbrev>
|
||
|
||
<partintro>
|
||
<section id="pgsql.intro">
|
||
&reftitle.intro;
|
||
<para>
|
||
PostgreSQL データベースはオープンソースのプロダクツであり、無料で
|
||
使用可能です。Postgres は元々 UCB(カリフォルニア大学バークレイ校)
|
||
コンピュータ・サイエンス学部で開発されたものです。この Postgres は、
|
||
現在いくつかの商用データベースにおいてサポートされつつある
|
||
オブジェクトリレーショナルデータベース的概念の多くの先駆けでした。
|
||
Postgres は、SQL92/SQL99 言語サポート・トランザクション・参照整合性・
|
||
ストアドプロシージャ・拡張可能な型を提供しています。PostgreSQLは、
|
||
バークレイ校での Postgres のオリジナルコードの、オープンソースの
|
||
子孫にあたります。
|
||
</para>
|
||
</section>
|
||
|
||
<section id="pgsql.requirements">
|
||
&reftitle.required;
|
||
<para>
|
||
PostgreSQL サポートを使用するには、PostgreSQL 6.5 以降が必要です。
|
||
PostgreSQL 8.0 以降では PostgreSQL モジュールの全ての機能を使用可能
|
||
です。PostgreSQL は、マルチバイト文字エンコーディングを含む多くの
|
||
文字エンコーディングをサポートしています。現在のバージョン及び
|
||
PostgreSQLに関するより詳細な情報は、
|
||
<ulink url="&url.pgsql;">&url.pgsql;</ulink> と
|
||
<ulink url="&url.pgsql.manual;">PostgreSQL Documentation</ulink>
|
||
で入手可能です。
|
||
</para>
|
||
</section>
|
||
|
||
&reference.pgsql.configure;
|
||
|
||
&reference.pgsql.ini;
|
||
|
||
<section id="pgsql.using">
|
||
<title>使用法およびヒント</title>
|
||
<warning>
|
||
<para>
|
||
通知メッセージを処理するコードにバグがあるため、PHP 4.0.6 で
|
||
PostgreSQL モジュールを使用することは推奨されません。
|
||
4.1.0 以降を使用してください。
|
||
</para>
|
||
</warning>
|
||
<warning>
|
||
<para>
|
||
PostgreSQL モジュールの関数名は、現在のコーディング標準に準拠する
|
||
ために 4.2.0 以降で変更されました。新しい関数名のほとんどには、
|
||
pg_lo_open() のようにアンダースコアが付きます。
|
||
いくつかの関数は、pg_exec() から pg_query() というように、統一を
|
||
とるために関数名が変更されます。
|
||
古い名前も 4.2.0 とそれに続くいくつかのバージョンで使用可能ですが、
|
||
将来的には削除される可能性があります。
|
||
</para>
|
||
<table>
|
||
<title>変更された関数名</title>
|
||
<tgroup cols="2">
|
||
<thead>
|
||
<row>
|
||
<entry>古い関数名</entry>
|
||
<entry>新しい関数名</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry><function>pg_cmdtuples</function></entry>
|
||
<entry><function>pg_affected_rows</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_errormessage</function></entry>
|
||
<entry><function>pg_last_error</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_exec</function></entry>
|
||
<entry><function>pg_query</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_fieldname</function></entry>
|
||
<entry><function>pg_field_name</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_fieldsize</function></entry>
|
||
<entry><function>pg_field_size</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_fieldnum</function></entry>
|
||
<entry><function>pg_field_num</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_fieldprtlen</function></entry>
|
||
<entry><function>pg_field_prtlen</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_fieldisnull</function></entry>
|
||
<entry><function>pg_field_is_null</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_freeresult</function></entry>
|
||
<entry><function>pg_free_result</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_getlastoid</function></entry>
|
||
<entry><function>pg_last_oid</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loreadall</function></entry>
|
||
<entry><function>pg_lo_read_all</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_locreate</function></entry>
|
||
<entry><function>pg_lo_create</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_lounlink</function></entry>
|
||
<entry><function>pg_lo_unlink</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loopen</function></entry>
|
||
<entry><function>pg_lo_open</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loclose</function></entry>
|
||
<entry><function>pg_lo_close</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loread</function></entry>
|
||
<entry><function>pg_lo_read</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_lowrite</function></entry>
|
||
<entry><function>pg_lo_write</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loimport</function></entry>
|
||
<entry><function>pg_lo_import</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_loexport</function></entry>
|
||
<entry><function>pg_lo_export</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_numrows</function></entry>
|
||
<entry><function>pg_num_rows</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_numfields</function></entry>
|
||
<entry><function>pg_num_fields</function></entry>
|
||
</row>
|
||
<row>
|
||
<entry><function>pg_result</function></entry>
|
||
<entry><function>pg_fetch_result</function></entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</table>
|
||
<para>
|
||
従来の <function>pg_connect</function>/<function>pg_pconnect</function>
|
||
構文は、将来的に非同期接続
|
||
機能をサポートするために過去のものとなる可能性があります。
|
||
<function>pg_connect</function>、<function>pg_pconnect</function>
|
||
では、接続文字列を使用してください。
|
||
</para>
|
||
</warning>
|
||
<para>
|
||
全ての関数が全ての構築環境でサポートされるわけではありません。
|
||
サポートされる関数は、使用する libpq(PostgreSQL の C クライアント
|
||
インターフェイス) のバージョンと libpq のコンパイル方法に依存します。
|
||
足りない関数がある場合、libpq はその関数を必要とする機能を
|
||
サポートしません。
|
||
</para>
|
||
<para>
|
||
接続する PostgreSQL サーバよりも新しい libpq を使用することも
|
||
重要です。使用する libpq のバージョンが PostgreSQL サーバが期待するよりも
|
||
古い場合、問題を生じる可能性があります。
|
||
</para>
|
||
<para>
|
||
バージョン 6.3(1998/3/2) 以降、PostgreSQL は UNIX ドメインソケットを
|
||
使用しています。TCP ポートをオープンしておく必要はありません。
|
||
これらの新しいコネクションの使用例を以下に示す表に
|
||
示します。このソケットは <filename>/tmp/.s.PGSQL.5432</filename> に
|
||
あります。このオプションは <command>postmaster</command> に対して'-
|
||
i' フラグを指定することで有効となります。これは "Unix ドメイン
|
||
のほかにソケット以外の TCP/IP ソケットもlisten する"という意味です。
|
||
<table>
|
||
<title>Postmaster と PHP</title>
|
||
<tgroup cols="3">
|
||
<thead>
|
||
<row>
|
||
<entry>Postmaster</entry>
|
||
<entry>PHP</entry>
|
||
<entry>ステータス</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry>postmaster &</entry>
|
||
<entry>pg_connect("dbname=MyDbName");</entry>
|
||
<entry>OK</entry>
|
||
</row>
|
||
<row>
|
||
<entry>postmaster -i &</entry>
|
||
<entry>pg_connect("dbname=MyDbName");</entry>
|
||
<entry>OK</entry>
|
||
</row>
|
||
<row>
|
||
<entry>postmaster &</entry>
|
||
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
||
<entry>
|
||
Unable to connect to PostgreSQL server: connectDB() failed:
|
||
Is the postmaster running and accepting TCP/IP (with -i)
|
||
connection at 'localhost' on port '5432'? in
|
||
/path/to/file.php on line 20.
|
||
</entry>
|
||
</row>
|
||
<row>
|
||
<entry>postmaster -i &</entry>
|
||
<entry>pg_connect("host=localhost dbname=MyDbName");</entry>
|
||
<entry>OK</entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</table>
|
||
</para>
|
||
<para>
|
||
PostgreSQL サーバへの接続は、以下のようにコマンド文字列の中に
|
||
値の組を羅列することにより、確立することができます。
|
||
<command>$conn = pg_connect("host=myHost port=myPort tty=myTTY
|
||
options=myOptions dbname=myDB user=myUser password=myPassword");
|
||
</command>
|
||
</para>
|
||
<para>
|
||
以前の構文:
|
||
<command>
|
||
$conn = pg_connect ("host", "port", "options", "tty", "dbname")
|
||
</command>
|
||
は古い構文であり、推奨されません。
|
||
</para>
|
||
<para>
|
||
環境変数は、PostgreSQL サーバ/クライアントの動作に影響を与えます。
|
||
例えば、PostgreSQL モジュールは、ホスト名が接続文字列で省略された
|
||
場合、環境変数 PGHOST を探します。サポートされる環境変数は、バージョン
|
||
毎に異なります。詳細は、PostgreSQL プログラマ用マニュアル(libpq -
|
||
環境変数)を参照ください。
|
||
</para>
|
||
<para>
|
||
適切なユーザ用に環境変数が設定されていることを確認してください。
|
||
カレントのプロセスで利用可能な環境変数を確認するには、
|
||
<literal>$_ENV</literal> または <function>getenv</function>
|
||
を使用してください。
|
||
</para>
|
||
<example>
|
||
<title>デフォルトのパラメータを設定する</title>
|
||
<programlisting>
|
||
<![CDATA[
|
||
PGHOST=pgsql.example.com
|
||
PGPORT=7890
|
||
PGDATABASE=web-system
|
||
PGUSER=web-user
|
||
PGPASSWORD=secret
|
||
PGDATESTYLE=ISO
|
||
PGTZ=JST
|
||
PGCLIENTENCODING=EUC-JP
|
||
|
||
export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD PGDATESTYLE PGTZ PGCLIENTENCODING
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
<note>
|
||
<para>
|
||
PostgreSQL は、識別子(例: テーブル名・カラム名)を自動的に小文字に
|
||
変換します。大文字として認識させるには、識別子を常にクォートする
|
||
必要があります。
|
||
</para>
|
||
</note>
|
||
</section>
|
||
|
||
&reference.pgsql.constants;
|
||
|
||
<section id="pgsql.examples">
|
||
&reftitle.examples;
|
||
<para>
|
||
PostgreSQL 7.1.0 から、text データ型の最大サイズは 1GB となっています。
|
||
古い PostgreSQL の text データ型はブロックサイズ(デフォルトは 8KB、最大
|
||
32KB をコンパイル時に定義可能)の制限を受けていました。
|
||
</para>
|
||
<para>
|
||
ラージオブジェクト(lo)インターフェースを使用するには、そのクエリーを
|
||
トランザクション・ブロックの中に入れてやる必要があります。
|
||
トランザクション・ブロックは <command>BEGIN</command> で始まり、
|
||
そのトランザクションが有効な場合は <command>COMMIT</command> または
|
||
<command>END</command> で終わります。トランザクションが失敗した場合、
|
||
そのトランザクションは <command>ROLLBACK</command> または
|
||
<command>ABORT</command> により閉じる必要があります。
|
||
<example>
|
||
<title>ラージオブジェクトの使用例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$database = pg_connect("dbname=jacarta");
|
||
pg_query($database, "begin");
|
||
$oid = pg_lo_create($database);
|
||
echo "$oid\n";
|
||
$handle = pg_lo_open($database, $oid, "w");
|
||
echo "$handle\n";
|
||
pg_lo_write($handle, "large object data");
|
||
pg_lo_close($handle);
|
||
pg_query($database, "commit");
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
ラージオブジェクトリソースを閉じる前に PostgreSQL サーバへの接続を
|
||
閉じないようにしてください。
|
||
</para>
|
||
</section>
|
||
</partintro>
|
||
|
||
&reference.pgsql.functions;
|
||
|
||
</reference>
|
||
|
||
<!-- 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:
|
||
-->
|