【发布时间】:2012-12-22 03:55:00
【问题描述】:
我正在尝试在 pSQL 表中插入一行,同时指定键和值作为占位符:
my @keys = keys %db_entr;
my @vals = values %db_entr;
my @items = (@keys, @values);
my $dbh = DBI->connect("DBI:Pg:dbname=testdb;host=localhost", "username", 'password', {'RaiseError' => 1});
my $sth = $dbh->prepare("INSERT INTO grid ( ?, ?, ? ) values ( ?, ?, ? )");
my $rows = $sth->execute(@items);
print "$rows effected\n";
但是,无论我做什么,这都会给我一个错误:
DBD::Pg::st execute failed: ERROR: syntax error at or near "$1"
LINE 1: INSERT INTO grid ( $1, $2, ...
^ at ./file.pl line 262, <STDIN> line 11.
有人知道我可能做错了什么吗?
【问题讨论】:
-
您的代码示例没有意义,您没有显示
@items的创建位置
标签: perl postgresql dbi