【发布时间】:2017-04-28 03:31:42
【问题描述】:
我需要将哈希值插入数据库。以下是我必须在 table1 列 key 和 value 中插入值的代码模板:
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;
我知道如何使用数组插入值,即使用execute_array(),但不知道如何在table1 中插入%hash 中存在的值。
有什么建议吗?
【问题讨论】:
-
%hash究竟包含什么? -
这有什么关系?它的定义与哈希的定义方式完全相同。
-
哈希的结构是问题的重要组成部分。您已经有两个不同的答案,来自对问题的不同理解的人,因为不清楚哈希中的内容。
-
%hash 定义为 $key,$value。
-
您的回答非常没有有帮助,这让我想知道您为什么拒绝向我们提供这些信息。您确实意识到
$value可能只是随便什么?