Windows
○SQLiteモジュールのDL
ppm ppm> install DBD-SQLite
○実行
Perl test.pl
Linux
○SQLiteモジュールのDL
perl -MCPAN -e shell b /DBD.*/ install DBD::SQLite
○プロキシの変更
cpan> o conf http_proxy http://プロキシ名:ポート番号 cpan> o conf ftp_proxy http://プロキシ名:ポート番号 cpan> o conf commit
○実行
Perl test.pl
コード
http://www.itsmemo.com/it/cgi/000075.html
のそのまま
1 |
#!/usr/bin/perl
use DBI;
$mydb = "testdb";
$hDB = DBI->connect(
"dbi:SQLite:dbname=$mydb","","",{PrintError=>0}
);
if(!$hDB){
print "$DBI::errstr \n";
exit;
}
# (1) データ取得のSQL文
$sql = "SELECT * FROM testtb WHERE id = ?";
my ($db_id, $db_name);
# Perlの変数を列に結び付ける
# (2) データ取得実行
$hst = $hDB->prepare($sql);
$hst->bind_columns(undef, \($db_id, $db_name));
if($hst){
for($id = 1; $id < 10; $id++){
$retval = $hst->execute($id);
if(!$retval){
print "error";
print $hDB->errstr . "\n";
last;
}
# @data = $hst->fetchrow_array;
$data = $hst->fetch;
print $data;
if (!$data) {
print $hDB->errstr . "\n";
last;
}
# print "$data[0], $data[1], $data[2]\n";
print "$db_id, $db_name\n";
}
print "finish";
$hst->finish;
}
else{
# エラー処理
print $hDB->errstr . "\n";
exit;
}
print "disconnect";
# $hDB->commit;
# $a = <STDIN>;
$hDB->disconnect; |
[カテゴリ: プログラミング言語 > Perl]
[通知用URL]
Tweet
最終更新時間:2009年05月22日 11時27分53秒