
用DBI就可以给你段代码:
use DBImy $dbname = "test"
my $location = "192.168.1.115"
my $port = "3306" #这是mysql的缺省
my $database = "DBI:mysql:$dbname:$location:$port"
my $db_user = "root"
my $db_pass = "123456"
my $dbh = DBI->connect($database,$db_user,$db_pass)
my $sql = "SELECT * FROM tablename"
my $sth = $dbh->prepare($sql)#准备
$sth->execute() or die "无法执行SQL语句:$dbh->errstr" #执行
while (@data = $sth->fetchrow_array()) {#fetchrow_array返回row
print "Email:$data[0]\t Telephone:$data[1]\n"
}
$sth->finish()
$dbh->disconnect#断开数据库连接
先在CMD方式下运行:http://ppm.tcool.org/archives/DBD-mysql.ppd安装DBI:mysql
在MYSQL配置正确的情况下就可以开始写了,以下是例子:
#!/usr/bin/perl
use DBI
$user="root"
$password="mscnyhlplayon"
$database="flash"#数据库
$telbase="game_flash"#表
my $dbh = DBI->connect("DBI:mysql:$database", $user, $password) or die "无法连接数据库: " . DBI->errstr
$sth=&MySQL_Query("select * from game_flash where id = 46")
$row = $sth->fetchrow_arrayref()
$test_txt= $row->[4]
#断开连接
$dbh->disconnect
print "$sth<br><br>$test_txt<br><br>$row"
print "</BODY></HTML>"
sub MySQL_Query {
my ($class,$command)=@_
$sth=$dbh->prepare("$class") || die &Lost($class,$dbh->errstr)
$sth->execute() || die &Lost($class,$dbh->errstr)
return($sth)
}
sub Lost {
my ($errsA,$errsB)=@_
print "$errsA<br><br>$errsB"
print "</BODY></HTML>"
exit
}
Oracle10g
集成
Perl,使用的是
5.8.3
版本,当你再独立安装
Perl,
并且不是
5.8.3
版时,在运行
Perl
-时就会出现途中的错误
修改环境变量
PERL5LIB
的值,把你自己安装的
Perl
的库路径也加到
PERL5LIB
中去
D:perllibD:perlsitelib
解决问题
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)