问题描述
$dbh->do (qq {
INSERT INTO todo SET t = Now(),status = 'open',content = ?
},undef,$content);
谁能解释一下?我想我了解整个代码,但不了解它的来源。
use warnings;
use strict;
use lib q(/data/TEST/perl/lib);
use CGI qw(:standard);
use WebDB;
sub insert_item {
my $content = shift;
my $dbh;
$content =~ s/^\s+//;
$content =~ s/^\s+$//;
if ($content ne "") {
$dbh = WebDB::connect();
$dbh->do (qq {
INSERT INTO todo SET t = Now(),$content);
$dbh->disconnect();
}
}
sub display_entry_form {
print start_form(-action=> url()),"To-do item:",br (),textarea ( -name => "content",-value => "",-override => 1,-rows =>3,-columns => 80),submit(-name=> "choice",-value => "Submit"),end_form();
}
print header(),start_html(-title=>"To-Do List",-bgcolor => "white"),h2("To-Do List");
my $choice = lc(param ("choice"));
if ($choice eq "") {
display_entry_form();
} elsif ( $choice eq "submit" ) {
insert_item(param("content"));
display_entry_form();
} else {
print p ("Logic error,unkNown choice: $choice");
}
解决方法
do()
方法接受 3 个参数:查询、查询属性和绑定数据。您示例中的 undef
表示没有要应用的属性。
$rows = $dbh->do($statement) or die $dbh->errstr;
$rows = $dbh->do($statement,\%attr) or die $dbh->errstr;
$rows = $dbh->do($statement,\%attr,@bind_values) or die ...