数据库操作问题perl
my $dbh = DBI-> connect( "DBI:mysql:$web_dataname ", "$web_dataroot ", "$web_datapass ", { RaiseError => 1 } );
$web_dataname 数据库名称
$web_dataroot 数据库用户名
$web_datapass 数据库密码
如何放数据库地址
use DBI;
use DBD::mysql;
use CGI qw( :standard );
顶部的引用
还有为什么运行不下去???
高手指点!
[解决办法]
use DBI;
$dbname = "myBooks ";
$dbhostname = "localhost ";
$dbport = 3306;
$dsn = "DBI:mysql:$dbname:$dbhostname:$dbport ";
$dbuser = "michael ";
$dbpassword = "secret ";
$dbh = DBI-> connect($dsn, $dbuser, $dbpassword);
$sql = "select title, author from cookbooksTable ";
@rowrefs = @{$dbh-> selectall_arrayref($sql)};
foreach (@rowrefs) {
my ($title, $author) = @{$_};
print "$title by $author\n ";
}
$dbh-> disconnect;