PDA

View Full Version : DBIからPgへの動作確認


youthful
2002/11/22, 04:12 PM
いつもお世話になってます。
s20サーバーでPostgreを使おうとしてるのですが
ここでスクリプトエラーがでます。
パーミッションは755です。
確認用に使ったCGI↓

#!/usr/local/bin/perl
use DBI;

$ds = "DBI:Pg:dbname=youthful:host=localhost";
$user = "youthful";
$pass = "パスワード";

$dbh = DBI->connect($ds,$user,$pass,{AutoCommit => 0}) ||
print $DBI::errstr . "\n";

---------------------------------------------------

http://youthful.s20.xrea.com/test.cgi
でスクリプトエラーがでます。
Script Error
The script did not produce proper HTTP headers. Please see the error log to see the detail of the errors. Depending on the server configuration, you can also run this script under CGIWrap debugging. Usually, either rename or link the script temporarily to a file which ends with .cgid extension, or add a AddHandler cgi-script-debug .cgi line to your .htaccess file.

------------------------------------------------------------

尚、データベース作成申請及び、sshでのテーブル作成・データの登録が
できることは確認済みです。

他のスレに似たようなケースがありました。
http://sb.xrea.com/showthread.php?threadid=3870
これと同じケースでしょうか?

上記以外にも書き方にミスがある場合。
よろしければお教え願えないでしょうか。

kzhr
2002/11/22, 04:20 PM
これでスクリプトは全てですか?

それならば、一番後ろに
print "content-type: text/plain\n\nOK";
とつけて試してみてください。

youthful
2002/11/22, 04:27 PM
すごい初歩的なとこで間違えてました。
もうしわけないです(^^;
すばやいレスありがとうございました。


#!/usr/local/bin/perl
use DBI;

$ds = "DBI:Pg:dbname=youthful:host=localhost";
$user = "youthful";
$pass = "パスワード";

$dbh = DBI->connect($ds,$user,$pass,{AutoCommit => 0}) ||
print $DBI::errstr . "\n";
print "content-type: text/plain\n\nOK";

youthful
2002/11/23, 03:37 AM
昨日の夕方投稿してから上記のソースに下の部分を追加しました。
しかしここでまたスクリプトエラーです。致命的な何かが足りてないようです。
-----------------------------------------------

$sth = $dbh->prepare ("select * from addrlist");
$sth->execute();

while (@outdata = $sth->fetchrow_array) {
print join "\t",@outdata,"\n";
}

$sth->finish();
$dbh->disconnect();

------------------------------------------------
色々と参考資料をみてソースを組み合わせたり試したのですが
何かが足りていないようで動きません。
本ではこれで表示されてるのですが(^^;
何かソースとは別の部分が抜けてるのでしょうか。
http://youthful.s20.xrea.com/test2.cgi
よろしければお教えください。:confused:

youthful
2002/11/24, 04:11 PM
malformed header from script. Bad header=No such file or directory: c:/program files/########/#####/######/#####/test2.cgi
DBI->connect(dbname=youthful:host=localhost) failed: connectDBStart() -- socket() failed: errno=2

上のスクリプトの接続を自分のサーバー用に設定して試したところ上のエラーがでます。
データーベースにファイルがないということなんでしょうか?

自分のサーバーのほうの場合ですと、
psql でログインして SELECT * FROM addrlist; を実行すれば、
name | email
------+-----------------
MOG | mog@***.***.com
JON | jon@***.***.net
(2 rows)
と、でますしソフトのCSEからでもデーターベースにアクセスしてみることもできたんですが(^^;

もちろんSSHでx20サーバーに接続した場合も SELECT * FROM addrlist; と打てば
name | email
------+-----------------
MOG | mog@***.***.com
JON | jon@***.***.net
(2 rows)
と返ってくるのですが。。
いったい何がおかしいのでしょう。。
よろしければ返信お願いします。

youthful
2002/11/25, 07:03 AM
FTPのパスワードいれてました。
SSHのキーをいれたらよかったんですよね。。
まだカギ作っていなかったのでパスワード無しにしたら動きました。。
できないからと騒いだりしてもうしわけないです。

まだ自分のサーバーが動いてないんですがこちらも頑張って動かしていきたいと思います。