perl连接mysql
我想学perl连接mysql,perl下载了DBIDBD-MYSQL,还需要做什么我已经安装了这2个包,但是运行报错,安装驱动失败,Perhapsarequiredsha...
我想学perl连接mysql,perl下载了DBI DBD-MYSQL,还需要做什么
我已经安装了这2个包,但是运行报错,安装驱动失败,Perhaps a required shared library or dll isn't installed where expected.
我的问题已解决,将libmysql.dll拷贝到system32下就好了,但是谁比较懂行等告诉我是什么原理么?
还是谢谢1楼的朋友。 展开
我已经安装了这2个包,但是运行报错,安装驱动失败,Perhaps a required shared library or dll isn't installed where expected.
我的问题已解决,将libmysql.dll拷贝到system32下就好了,但是谁比较懂行等告诉我是什么原理么?
还是谢谢1楼的朋友。 展开
1个回答
展开全部
下载以后需要安装,安装方法可以参考文章:http://hi.baidu.com/wtc%5Fwh/blog/item/6c514fdf84f1fd114854035f.html
安装好了就可以使用了,例子程序如下:
#!/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;#断开数据库连接
补充:
拷贝文件到SYSTEM32不是最好的办法,其实在环境变量PATH里面加入MYSQL的DLL文件目录即可。
安装好了就可以使用了,例子程序如下:
#!/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;#断开数据库连接
补充:
拷贝文件到SYSTEM32不是最好的办法,其实在环境变量PATH里面加入MYSQL的DLL文件目录即可。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询