我有一个包含sql update查询类型的perl脚本,但是我无法导致结果,我打破了头部3天,我没有找到解决方案,有人帮助我
my $sth = $db->prepare('select idS from ocs.Storage where name like ? ');
$sth->bind_param(1,"$v4");
$sth->execute();
if ($sth->rows < 0)
{
print " sorry";
}
else
{
#print "found n",$sth->rows;
while (my $results = $sth-> fetchrow_hashref)
{
$idSt = $results->{idS};
print "idst est $idSt et vm name est $test3[$d]";
$idSt=~ s/^s+|s+$//;
$idSt=~ s/'//g;
$idSt=~ s/'//g;
$idSt=~ s/"//g;
$idSt=~ s/^s+//;
$idSt=~ s/s+$//;
my $null=0;
$idSt=$idSt +$null;
my $statement1 = "UPDATE VM SET stoaregeA_id = ? where VM_OS = ?";
$db5->do($statement1,undef,$idSt,$test3[$d]);
}}
您确定$db5
指向正确的数据库吗?
确保您有strict
,并且warnings
打开。
此外,要进一步诊断并查看mysql
上实际运行的查询,请运行以下SQL命令:
-- Log all queries
set global general_log = 'ON';
set global log_output = 'TABLE';
-- Run after code execution
select * from mysql.general_log;
尝试为您的代码添加更多检查,看看是否会给您更多。另外,请让我们看看$test3[$d]
和$db5
是什么。还包括您的表格描述。可能是那里可以给我们一个线索的东西。
my $sth = $db->prepare('SELECT idS FROM ocs.Storage WHERE name LIKE ?')
or die("Error preparing: " . $db->errstr);
$sth->bind_param(1, "$v4");
$sth->execute
or die("Error executing: " . $sth->errstr);
if ($sth->rows < 0) {
print " sorry";
} else {
while (my $results = $sth->fetchrow_hashref) {
$idSt = $results->{idS};
print "idst est $idSt et vm name est $test3[$d]";
$idSt=~ s/^s+|s+$//;
$idSt=~ s/'//g;
$idSt=~ s/'//g;
$idSt=~ s/"//g;
$idSt=~ s/^s+//;
$idSt=~ s/s+$//;
my $null = 0;
$idSt = $idSt + $null;
my $stmt = 'UPDATE VM SET stoaregeA_id = ? WHERE VM_OS = ?';
$db5->do($stmt, undef, $idSt, $test3[$d])
or die("Error doing: " . $db5->errstr);
}
}
如果参数化更新不起作用,请尝试直接构造最终语句,然后将其打印为调试。