我写下了一个永久单元:
package sql;
use strict;
use XML::Simple;
use DBI;
use DBD::mysql;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(DBImport DataFill);
our @EXPORT = qw(DBImport DataFill);
our $dbh;
sub DBConnect() {
my $platform = "mysql";
my $database = "databasename";
my $host = "localhost";
my $user = "user";
my $pw = "password";
my $dsn = "dbi:mysql:$database:localhost";
$dbh = DBI->connect($dsn, $user, $pw);
$dbh->do( SET NAMES utf8 );
return $dbh;
}
sub Query($) {
my $sth = $dbh->prepare(shift);
$sth->execute;
while (my $ref = $sth->fetchrow_hashref()) {
print $ref->{ email };
}
$sth->finish();
}
BEGIN{
$dbh = &DBConnect();
}
END{
$dbh->disconnect();
}
1;
并且一经尝试使用:
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use sql;
&Query("SELECT * FROM users");
但它没有工作。
错误信息: 不详的路段: Query calls at /var/www/domains/gabordx.tauri.hu/www/main.pl line 7. ->“&Query(从用户中选取”);”
问题是什么?
感谢!