我想打印我的perl脚本的所有sql结果,我已经连接到数据库,并且想显示sql查询的结果:
MySQL("SELECT * FROM test");
# define subroutine to submit MySQL command
sub MySQL
{
#Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=database;host=ip","login",'password',{'RaiseError' => 1});
my $query = $_[0]; #assign argument to string
my $sth = $prepare($query); #prepare query
$sth->execute(); #execute query
while (my @row = $sth->fetchrow_array)
{
print "@row\n";
}
}
我有这个错误:
Global symbol "$prepare" requires explicit package name at test3.pl line 34.
syntax error at test3.pl line 34,near "$prepare("
Global symbol "$sth" requires explicit package name at test3.pl line 36.
Execution of test3.pl aborted due to compilation errors.