我正在尝试以表格格式在网页上打印数据库表的所有值。我正在使用具有 .cgi 扩展名的 perl 文件。每当我尝试运行代码时,我都会收到错误“全局符号需要显式包名称”。数据库表的行应该显示 onLoad 但它没有发生..
我已经尝试了很多,但无法理解代码有什么问题..
请帮忙..
people.cgi 文件的代码..
#!/usr/bin/perl
use CGI;
use DBI;
use strict;
use warnings;
print "Content-type:text/html\r\n\r\n";
#$q = CGI->new;
#print $q->header;
my $dsn = "DBI:mysql:Demo:localhost"; # Data source name
my $username = "mint"; # User name
my $password = "MINT123"; # Password
my $dbh;
my $sth; # Database and statement handles
$dbh = DBI->connect($dsn, $username, $password);
$sth = $dbh->prepare("SELECT * from people");
$sth->execute();
print "<h1>ganesh</h1>";
print "<table >
<tr>
<th>ID</th>
<th>Name of People Involved</th>
<th>Position</th>
<th>Roles(A user can have multiple roles)</th>
<th>Notes</th>
</tr>";
while( $href = $sth->fetchrow_hashref ) {
print "<tr>";
print "<td>$$href{'id'}</td>";
print "<td>$$href{'name'}</td>";
print "<td>$$href{'pos'}</td>";
print "<td>$$href{'role'} </td>";
print "<td>$$href{'notes'}</td>";
#print "<td><input type='text' value=\"$$href{'display_name'}\" id =\"dis-$$href{'windows_id'}\" readonly> </td>";
#print "<td><input type='text' value=\"$$href{'email_id'}\" readonly> </td>";
print "</tr>";
}
print "</table>";
$sth->finish();
$dbh->disconnect();
错误信息..
Global symbol "$href" requires explicit package name at people.cgi line 31.
Global symbol "$href" requires explicit package name at people.cgi line 34.
Global symbol "$href" requires explicit package name at people.cgi line 35.
Global symbol "$href" requires explicit package name at people.cgi line 36.
Global symbol "$href" requires explicit package name at people.cgi line 37.
Global symbol "$href" requires explicit package name at people.cgi line 38.
Execution of people.cgi aborted due to compilation errors.
我的 MYSQL 表的结构..它有 14 列...里面没有数据...