2016-07-20 7 views
1

Perl에서 이전 Mysql 라이브러리를 사용하는 몇 가지 오래된 코드가 있습니다.Convert -> Perl에서 DBD :: mysql과 함께 사용하는 numrows

대부분 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. 
} 

이 오류 I입니다 돌아옴 :

,

꼬리 /var/log/apache2/error.log

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

아래로 사용한다고 생각 http://p3rl.org/DBI) : SELECT 문에서 데이터베이스 엔진 내에서 쿼리를 단순히 "시작"합니다. execute를 호출 한 후 fetch 메소드 중 하나를 사용하여 데이터를 검색하십시오. execute 메소드는 (대부분의 데이터베이스가 미리 말할 수 없기 때문에) 쿼리가 반환 할 행의 수를 반환하지 않으며, 단순히 참값을 반환합니다. – choroba

+1

'$ sth-> execute ($ type); $ numRows = $ sth-> rows; if ($ numRows) {print "Success!";}'이렇게하면됩니다. – AbhiNickz

답변

0

난 당신이 [DBI (에서

if ($sth->rows)