perlを使用して単純なDBI接続を機能させるのに問題があります。
プレースチェッカーを配置して、データベースハンドルが未定義であり、常に未定義であるかどうかを確認します。露骨なエラーはありますか?私はphpスクリプトで使用しているので、入力した情報は正しいと確信しています。
#!/usr/bin/perl -w
use warnings;
print "Content-Type: text/html\n\n";
use DBI;
# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=db_name;host=host_name";
$dbh = DBI->connect($dsn,"username","password");
if(defined $dbh)
{
print "Yes<br />";
}
else
{
print "No<br />";
}
# Select the data and display to the browser
$sth = $dbh->prepare("SELECT * FROM customer");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'cid'}";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();