我当前的perl代码正在运行数据库查询的所有行,然后抛出一个
DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at ./recieveTxn.cgi
line 168.
Run Code Online (Sandbox Code Playgroud)
在末尾.它几乎就像有些东西没有告诉循环在行的末尾停止,但我已经像其他人一样写了它.
例如:查询会拉高
shortcode1
shortcode2
shortcode3
然后在这里抛出错误
$sql = "
SELECT
aPI.folder AS aPIfolder,
aPI.rowNum AS aPIrowNum,
hasInput,
evalCode
FROM
aPersonalItems as aPI
LEFT JOIN
pItems_special_inputs as SI
ON
aPI.folder = SI.folder AND
aPI.rowNum = SI.rowNum
WHERE
hasInput=1 AND
aPI.folder='$FORM{'folder'}'
ORDER BY
aPI.rowNum
";
$sth = $dbh->prepare( $sql );
$sth->execute();
my ($shortcoderow, $row);
my $shortcodeSQL = "
SELECT
*
FROM
pItemsShortCodes
WHERE
folder='$FORM{'folder'}'
ORDER BY
rowNum
";
my $shortcodeSTH = $dbh->prepare( $shortcodeSQL );
$shortcodeSTH->execute();
while( my $ref = $sth->fetchrow_hashref() ) {
my $shortCode;
my $isblank = 1;
my $rowNum = $ref->{'aPIrowNum'};
while(my $shortcodeRef = $shortcodeSTH->fetchrow_hashref())
#&& $rowNum == $shortcodeRef->{'rowNum'}) #line 168 above
{
$shortCode=$shortcodeRef->{'shortcode'};
print $shortCode."\n";
}
$shortcodeSTH->finish();
}
Run Code Online (Sandbox Code Playgroud)
问题是您正在处理多行$sth.
您的代码从中获取一行$sth,然后您的代码循环遍历每一行$shortcodeSTH,直到没有更多行.然后你的代码调用finish()方法$shortcodeSTH.(这是规范模式,因为您已经获取了所有行.)
然后,您的代码第二次从外部循环开始,从中获取第二行$sth.当您的代码$shortcodeSTH第二次尝试通过循环开始时,您已经获取了所有行并关闭了语句句柄.没有任何行要检索.(如果您没有发出对该finish()方法的调用,则返回的错误会有所不同;错误消息将是关于从游标末尾获取,或者已经获取最后一行,或者某种类似的东西.)