我是第一次使用 DBI(并且没有多久开始使用 Perl [2 周]),我似乎无法从数据库中获得任何结果。这是我所拥有的:
if( defined( $get{findAllPages} ) && defined( $post{ki} ) ){
my ($database, $hostname, $port, $password, $user );
$database = "#########";
$hostname = "localhost";
$password = "#########";
$user = "###########";
my $KI = $post{ki};
# connect to the database
my $dsn = "DBI:mysql:database=$database;host=$hostname;";
my $dbh = DBI->connect($dsn, $user, $password);
my $sth = $dbh->prepare("SELECT * FROM accounts WHERE KI = '" . $dbh->quote($KI) . "' ") or die "Could not select from table";
$sth->execute();
if( $sth->rows != 0 ) {
my $ref = $sth->fetchrow_hashref();
my $domain = $ref->{website};
my $DB_username = $ref->{db_name};
my $DB_password = $ref->{db_pass};
$sth->finish();
$dbh->disconnect();
print "domian: " . $domain . "<br />\n";
chomp(my $url = trim($domain));
就目前而言,它会检查是否KI
正确,然后检查行数是否有效。我无法工作的一点是从数组中返回值;
my $ref = $sth->fetchrow_hashref();
my $domain = $ref->{website};
my $DB_username = $ref->{db_name};
my $DB_password = $ref->{db_pass};
如果有人可以让我知道我哪里出错了,将不胜感激。