我創建數據庫舞者::教程連接到SQLite的
sqlite3 database
create table if not exists entries (
id integer primary key autoincrement,
title string not null,
text string not null
);
^D
我應該在哪裏把這個數據庫? 後
sub connect_db {
my $dbh = DBI->connect("dbi:SQLite:dbname=".setting('database')) or
die $DBI::errstr;
return $dbh;
}
sub init_db {
my $db = connect_db();
my $schema = read_file('./schema.sql');
$db->do($schema) or die $db->errstr;
}
get '/' => sub {
my $db = connect_db();
my $sql = 'select id, title, text from entries order by id desc';
my $sth = $db->prepare($sql) or die $db->errstr;
$sth->execute or die $sth->errstr;
template 'show_entries.tt', {
'msg' => get_flash(),
'add_entry_url' => uri_for('/add'),
'entries' => $sth->fetchall_hashref('id'),
};
};
收到一個錯誤 運行時錯誤 附近的 「辦公桌」:在/home/ultramozg/App/lib/App.pm 40行語法錯誤,行16
什麼這是我的錯?
'desk'不會出現在您呈現的任何地方。什麼是lib/App.pm的第40行? – ikegami
第40行my $ sth = $ db-> prepare($ sql)或者$ db-> errstr; –
哼哼....這聽起來不像是來自DBI的錯誤,但如果你堅持,'$ sql'中有什麼? – ikegami