ペット情報データベースシステム

---- SQLによる検索結果の表示プログラム ----


プログラム名
SQLによる検索結果の表示
プログラム番号
pet22.cgi
入力
SQL命令(パラメータとして渡される)
出力画面
処理内容
  1. パラメータで指定されたSQL命令をそのまま実行する。
  2. その結果をすべて表示する。
  3. 検索結果の件数を結果一覧の最初の行に表示する。
プログラム例
#!/usr/bin/perl
#--------------------
# program-ID:pet22.cgi
# auther    :nakamoto hiroyuki
# date      :2001/02/6
#--------------------

use CGI;
use DBI;

$query=new CGI;
$txt01 = $query->param('TXT01');

$username="egi";
$dbh = DBI->connect("dbi:Pg:dbname=egi",$username)
 or die "cannot prepare: " , $DBI->errstr();

$sth = $dbh->prepare("$txt01")
 or die "cannot prepare: " , $dbh->errstr();

$sth->execute() or die "cannot execute: " , $sth->errstr();

print "content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>検索結果</TITLE>\n";
print "</HEAD>\n";
print "<BODY bgcolor=LINEN>\n";
print "<center>\n";
print "<H3><font color=red>\n";
print ".......データベースの検索結果.......\n";
print "</font><H3>\n";
print "</center>\n";
#print "<p>\n";
print "<BR>\n";
print "<HR>\n";
@rows = $sth->rows;
print "<h4>\n";
print "<font color=red>\n";
print "検索数 : @rows 件\n";
print "</font>";
print "</h4>\n";
print "<HR>\n";
print "<H4>\n";
while( @row = $sth->fetchrow_array()){
  print "@row\n";
  print "<BR>\n";
}
print "<HR>\n";
print "</BODY>\n";
print "</HTML>\n";
 



江木鶴子 : egi@ube-c.ac.jp