我需要将哈希值插入数据库。以下是我必须在 table1 列键和值中插入值的代码模板:
use DBI;
use strict;
%hash; #assuming it already contains desired values
my $dbh = DBI->connect(
"dbi:Sybase:server=$Srv;database=$Db",
"$user", "$passwd"
) or die sprintf 'could not connect to database %s', DBI->errstr;
my $query= "Insert INTO table1(key, values) VALUES (?,?) ";
my $sth = $dbh->prepare($query)
or die "could not prepare statement\n", $dbh->errstr;
$sth-> execute or die "could not execute", $sth->errstr;
我知道如何使用数组即 use 插入值execute_array()
,但不知道如何插入%hash
table1 中存在的值。
有什么建议么?