I have some old code that uses the old Mysql
library in Perl.
Most of the time updating the code to use DBD::mysql
instead works with no problems however I have run into an issue where ->numrows
does not work.
What should I do to get the same functionality whilst using DBD::mysql
use 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.
}
use 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.
}
This is the error I get back:
tail /var/log/apache2/error.log
Can't locate object method "numrows" via package "DBI::st"
我认为你应该使用它如下
if ($sth->rows)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.