[pgsql-jp: 27992] CGIからの利用について
Takeuchi
takeu-al @ tf6.so-net.ne.jp
2002年 11月 18日 (月) 01:32:07 JST
take と申します。
VineLinux2.5 を使用しております。
[take @ localhost take]$ uname -a
Linux localhost.localdomain 2.4.18-0vl3 #1 Thu Mar 7 18:23:04 JST 2002
i686 unknown
まず、環境についてですが
postgres ユーザーの .bash_profile へ操作設定の記述
PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
export POSTGRES_HOME=/usr/local/pgsql
export PGDATA=/home/postgres/data
export PGLIB=/usr/local/pgsql/lib
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
DBI、DBD::Pg 等のモジュールのインストールは終わっております。
質問したい事は
「CGIからのPostgreSQLの利用」についてです。
まず、プログラムの方を簡単に説明します。
testuser という名前でユーザー、testdbという名前でデータベースを作成しまし
た。
例として次のような簡単なアドレス帳データを登録しました。
name email
MOG mog@***.***.com
JON jon@***.***.net
/usr/local/apache/cgi-bin/
にtestdb1.cgi
をおきました。
%su
#su - postgres
$postmaster &
でpostmaster を起動しました。
そして、アパッチを起動後
/usr/local/apache/bin/apachectl start
ブラウザから
http://localhost/cgi-bin/testdb1.cgi
とすると以下のようなエラーメッセージが表示されます。
Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, take @ localhost.localdomain and
inform them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error log.
Apache/1.3.26 Server at localhost.localdomain Port 80
----------------------------------------------------------------
自分自身では、Web からどうやってPostgreSQLをよぶのかがいまいち
理解できておりません。
そもそも、CGIを実行する際には
Postgres ユーザで実行しなきゃいけないのか、
[take @ localhost take]のままでは実行できないのかがわかりません。
#su - postgres
$postmaster &
でpostmaster を起動しました。
あたりの操作が間違っているのではないかと思っております。
何か私が勘違いしている点が御座いましたらご教授お願いいたします。
---------------以下ソースプログラム-------------------------------
#!/usr/bin/perl
use DBI;
$DB_user = 'testuser';
$DB_name = 'testdb';
$TABLE_name = 'addrlist';
$DB_pwd = '';
$mydb = DBI->connect("dbi:Pg:dbname=$DB_name","$DB_user","$DB_pwd");
$sth = $mydb->prepare("SELECT * FROM $TABLE_name");
$sth->execute();
$rows = $sth->rows();
print <<EOM;
Content-type: text/html
<html>
<head><title>データベーステスト</title></head>
<body>
<h3>データベース接続テスト</h3>
<hr>
<table border="1">
<tr><th>NAME</th><th>E-MAIL</th></tr>
EOM
for ($i = 0; $i < $rows; $i++) {
($name,$email) = $sth->fetchrow_array();
print <<EOM;
<tr><td>$name</td><td>$email</td></tr>
EOM
}
print <<EOM;
</body>
</html>
EOM
$sth->finish();
$mydb->disconnect();
exit();
pgsql-jp メーリングリストの案内