您的位置:首页 > 数据库 > MySQL

perl连接查询mysql

2010-04-14 10:06 525 查看
使用perl的语法如下:

#!C:/perl/bin/perl
use CGI qw(:standard);
use Mysql;
print header();
#Import the CGI parameters into the $Q structure
import_names();
#Connect to Andrew's MySQL server at Napier University
my $dbh = DBI->connect("dbi:mysql:database=gisq;host=pc236nt.napier.ac.uk;port=3306",
"scott", "tiger");
my $sth = $dbh->prepare("SELECT DISTINCT region FROM cia");
$sth->execute;
print "<h1>Here are some regions</h1>/n";
while (my ($region) = $sth->fetchrow_array()){
print "<a href="?region=$region" mce_href="?region=$region">$region<a><br/>/n";
}
if ($Q::region) {
print "<h1>Here are the countries of $Q::region</h1>";
my $sth = $dbh->prepare("SELECT name, population FROM cia where region=?");
$sth->execute($Q::region);
while (my ($name,$pop) = $sth->fetchrow_array()){
print "$name $pop<br/>/n";
}
}
$dbh->disconnect;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: