gpt4 book ai didi

mysql - 转换 ->numrows 以便在 Perl 中与 DBD::mysql 一起使用

转载 作者:行者123 更新时间:2023-11-30 22:15:21 27 4
gpt4 key购买 nike

我有一些旧代码使用 Perl 中的旧 Mysql 库。

大多数情况下更新代码以使用 DBD::mysql 而不是没有问题,但是我遇到了 ->numrows 不起作用的问题。

我应该怎么做才能在使用 DBD::mysql 时获得相同的功能

使用Mysql

use Mysql;

$type = "yellow";

$statement = "select name from customer where type = '$type'";

$sth = $dbh->query($statement);

if ($sth->numrows) {
print "Success!"; # This does work.
}

使用 DBD::mysql

use DBI;
use DBD::mysql;

$type = "yellow";

$statement = "select name from customer where type = ?";

$sth = $dbh->prepare($statement);
$sth->execute($type);

if ($sth->numrows) {
print "Success!"; # This doesn't work.
}

这是我返回的错误:

尾部/var/log/apache2/error.log

 Can't locate object method "numrows" via package "DBI::st"

最佳答案

我认为你应该像下面这样使用它

if ($sth->rows)

关于mysql - 转换 ->numrows 以便在 Perl 中与 DBD::mysql 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38476186/

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