【发布时间】:2020-02-29 19:50:12
【问题描述】:
我想打印我的 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.
【问题讨论】:
-
请阅读DBI documentation了解如何使用
prepare