#!/usr/bin/perl
use DBI;
my $dbname = "db_name";
my $location = "localhost";
my $port = "3306"; #这是mysql的缺省
my $database = "DBI:mysql:$dbname:$location:$port";
my $db_user = "root";
my $db_pass = "db_password";
my $dbh = DBI->connect($database,$db_user,$db_pass);
my $sql = "SELECT first_name,last_name FROM $table ORDER BY first_name";
my $sth = $dbh->prepare($sql);
#结果保存在$sth中
$sth->execute() or die "无法执行SQL语句:$dbh->errstr";
$dbh->disconnect;#断开数据库连接
|