use DBI;
my $dbh = DBI->connect('dbi:PgPP:dbname=$dbname', '', ''');
# 詳しくはDBIモジュールのドキュメントを参照してください
DBD::PgPPはPerlだけで記述したPostgreSQLデータベース用のクライアントイ ンターフェイスです。このモジュールはPostgreSQLのサーバとクライアントが 交わすネットワークプロトコルを実装しているので、libpq など他の PostgreSQLクライアントライブラリを必要としません。つまりこのモジュール はPostgreSQLが移植されていないOSから、PostgreSQLと通信できるのです。
このドキュメントはDBD::PgPPに特化した部分や制限について説明するもので、 すべてを網羅するリファレンスではありません。このドキュメントを読む前に まずDBIモジュールのマニュアルを読んでください。
データベースに接続するための最低限のパラメータは次のとおりです:
$dbh = DBI->connect('dbi:PgPP:dbname=$dbname', '', '');
このパラメータはユーザ認証を必要としないlocalhostの$dbnameデータベース に接続します。これはPostgreSQLのデフォルトの設定で利用できます。
connect()に関するパラメータは次のとおりです:
$dbh = DBI->connect(
"dbi:PgPP:dbname=$dbname",
$username, $password
);
$dbh = DBI->connect(
"dbi:PgPP:dbname=$dbname;host=$host;port=$port",
$username, $password
);
$dbh = DBI->connect(
"dbi:PgPP:dbname=$dbname;path=$path;port=$port",
$username, $password
);
パラメータ | デフォルト値
-----------+-------------------
dbname | current userid
host | localhost
port | 5432
path | /tmp
debug | undef
hostパラメータを使用する場合は、対象となるホストの postmaster を
-iオプション(TCP/IPソケット)で起動しておく必要があります。
ユーザ名とパスワードを使用する認証は、サーバ側のpg_hba.confで適切な 設定を行う必要があります。認証方法についてはpg_hba.confとpg_passwd のマニュアルページを参照してください。
このモジュールは次のOSでテストが完了しています。
with MacPerl5.6.1r1 built for PowerPC
with perl v5.6.0 built for darwin =item * Windows2000
with ActivePerl5.6.1 build631.
with perl v5.6.1 built for i386-freebsd
with perl v5.6.1 built for i386-freebsd
with perl v5.005_03 built for i386-freebsd
with perl v5.005_03 built for ppc-linux
with perl5.6.1 built for sun4-solaris.
with perl5.004_04 built for sun4-solaris.
Solaris2.6上のperl5.004_04は make testで失敗しますが使用することが できます。
このモジュールは次のモジュールを必要とします:
L<DBI>, L<IO::Socket>
DBI, http://developer.postgresql.org/docs/postgres/protocol.html
Hiroyuki OYAMA <oyama@cpan.jp>
Copyright (C) 2002 Hiroyuki OYAMA. Japan. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.