I wrote a perl module:
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;
and i tried use it:
#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use sql;
&Query("SELECT * FROM users");
but it don’t working.
error message: Undefined subroutine &main::Query called at /var/www/domains/gabordx.tauri.hu/www/main.pl line 7. -> “&Query(“SELECT * FROM users”);”
What is the problem with?
Thanks!
You need to export
Queryas well, like this:Otherwise you should refer it through
sqlpackage, like this