TripletaiL Japanese Web Application Framework
DBに接続し、SELECT文を発行し、情報を取得してみましょう。
以下を前提条件とします。
test
user
pass
CREATE TABLE TripletaiL_DB_Test (
id BLOB,
val1 BLOB,
val2 BLOB
);
INSERT INTO TripletaiL_DB_Test (id, val1, val2) VALUES ('test1', 'test2', 'test3');
INSERT INTO TripletaiL_DB_Test (id, val1, val2) VALUES ('test1', 'test4', 'test5');
#!/usr/local/bin/perl
use strict;
use warnings;
use Tripletail qw(tl.ini);
$TL->startCgi(
-DB => 'DB',
-main => \&main,
);
sub main
{
my $t = $TL->newTemplate('template.html', 'utf8');
my $DB = $TL->getDB('DB');
my $hash = $DB->selectAllHash(q{
SELECT
val1,
val2
FROM
TripletaiL_DB_Test
WHERE
id = ?
}, 'test1');
foreach my $key (@$hash){
$t->node('list')->node('val1')->add(
VAL => $key->{val1},
);
$t->node('list')->node('val2')->add(
VAL => $key->{val2},
);
$t->node('list')->add;
}
$t->flush;
}
[TL]
[DB]
type = mysql
defaultset = SET_Default
SET_Default = CON_DBRW
[CON_DBRW]
host = localhost
user = user
dbname = test
password = pass
<!DOCTYPE html>
<HTML>
<BODY>
<!begin:list>
<!begin:val1>
VAL1 : <&VAL>,
<!end:val1>
<!begin:val2>
VAL2 : <&VAL>,
<!end:val2>
<BR>
<!end:list>
</BODY>
</HTML>