gpt4 book ai didi

perl - DBD::mysql::st fetchrow_array 失败:fetch() 没有execute()

转载 作者:行者123 更新时间:2023-12-02 14:57:50 26 4
gpt4 key购买 nike

fetchrow_hashref 工作正常,但是当我使用 fetchrow_array 时出现以下错误。

#!/usr/bin/perl

use warnings;
use DBI;

$DB_name = 'database';
$DB_user = 'root';
$DB_pwd = '';
my $dsn = 'dbi:mysql:avm:localhost:3306';

$dbh = DBI->connect($dsn,"$DB_user","$DB_pwd");

print "\nConnection error: $DBI::errstr\n\n";

$sth = $dbh->prepare("SELECT * FROM tblmanufacturer");
$sth->execute();

while ( ($id,$name) = $sth->fetchrow_array() )
{
print "$id\t\t $name \n";
}

$sth->finish();

$dbh->disconnect();

DBD::mysql::st fetchrow_array failed: fetch() without execute() at

最佳答案

我总是在“执行”和“准备”错误时使用“die”。

$sql = $dbh->prepare( $query ) or die "Unable to prepare $query" . $dbh->errstr;
$sql->execute() or die "Unable to execute '$query'. " . $sql->errstr;

关于perl - DBD::mysql::st fetchrow_array 失败:fetch() 没有execute(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7598808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com