大佬教程收集整理的这篇文章主要介绍了perl操作数据库,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#!perl use Strict; use warnings; use utf8; use Encode; use DBI; my $dsn="DBI:mysql:database=test;host=localhost;port=3306"; my $user="root"; my $password="123456"; #连接数据库 my $dbh=DBI->connect($dsn,$user,$password,{'RaiseError'=>1}); #设置客户端编码 $dbh->do("SET character_set_client = 'utf8'"); $dbh->do("SET character_set_connection = 'utf8'"); $dbh->do("SET character_set_results= 'utf8'"); #执行查询 my $sth=$dbh->prepare("SELEct ename from emp"); $sth->execute(); #处理结果集 while(my $ref=$sth->fetchrow_hashref()){ #encode,decode用来转换编码 print encode("gbk",decode("utf8",$ref->{'ename'})),"\n"; } #断开连接 $sth->finish(); $dbh->disconnect();
以上是大佬教程为你收集整理的perl操作数据库全部内容,希望文章能够帮你解决perl操作数据库所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。