또한 dbConnect가 정의되지 않은 오류가 발생합니다. 문제를 찾을 수없는 것 같습니다. dbConnect는 암호가있는 하드 코드입니다.Perl 이름과 CPAN이 일치하지 않습니다.
#! perl
use strict;
use warnings;
use diagnostics;
use DBR qw(dbConnect query);
my $dbhead = dbConnect();
my $sql = "select * from mailing";
my @returned = query($dbhead,$sql);
DB.pm.라는 이름의 저장 디렉토리 에 저장 모듈 나는 이름이나 내용을 바꿀 수 없다.
package GUI::DB;
use strict;
use DBI;
use warnings;
use vars qw(@ISA @EXPORT);
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(dbConnect query);
#
# dbConnect - connect to the database, get the database handle
#
sub dbConnect {
# Read database settings from config file:
my $dsn = "DBI:mysql:database=test";
my $dbh = DBI->connect($dsn,
'abc',
'password',
{ RaiseError => 1 }
);
return $dbh;
}
#
# query - execute a query with parameters
# query($dbh, $sql, @bindValues)
#
sub query {
my $dbh = shift;
my $sql = shift;
my @bindValues = @_; # 0 or several parameters
my @returnData =();
# issue query
my $sth = $dbh->prepare($sql);
if (@bindValues) {
$sth->execute(@bindValues);
} else {
$sth->execute();
}
if ($sql =~ m/^select/i) {
while (my $row = $sth->fetchrow_hashref) {
push @returnData, $row;
}
}
# finish the sql statement
$sth->finish();
return @returnData;
}
__END__
나는 누군가 내가 잘못하고있는 곳을 볼 수 있기를 바라고 있습니다. 나는 모듈의 서브 루틴이 제대로 작동한다는 것을 알고있다. 모듈의 맨 아래에 코드를 작성하고 실행하면된다.
DB는 모듈에 대해 매우 나쁜 이름입니다. DB는 CPAN의 일부 무작위적인 것이 아닙니다. Perl 디버거를 위해 예약 된 네임 스페이스입니다. – hobbs
패키지 DB에서 펄에서 다르게 작동하는 몇 가지 사항이 있다고 생각합니다. – ysth
DB.pm의 처음 12 줄 정도를 표시 할 수 있습니까? – ysth