[英]Can't locate DBD/mysql.pm in @INC
I have installed latest version of Perl from ActiveState version 5.18.2.1802 successfully. 我已经从ActiveState版本5.18.2.1802成功安装了最新版本的Perl。 I am using Mysql database at back end in windows 8 environment.
我在Windows 8环境中在后端使用Mysql数据库。 Wrote down the following code
写下以下代码
#!/usr/local/bin/perl
use CGI;
use DBI;
$cgiObj = CGI->new;
print $cgiObj->header('text/html');
$params = 'DBI:mysql:world:localhost';
$user = 'root';
$pass = 'XXXXXX!';
$conn = DBI->connect($params, $user, $pass);
$sql='select * from city';
$query =$conn->prepare($sql);
$query->execute;
while(@row=$query->fetchrow_array)
{
print "ID: $row[0], Name: $row[1]<br>\n";
}
Please some one give me guidence 请有人给我指导
Presumably you haven't installed DBD::mysql. 大概您尚未安装DBD :: mysql。 But that assumes you have mistyped the error message (it would be "Can't locate DBD/mysql.pm", not "Can't locate DBD/Mysql.pm").
但这假定您输入了错误消息(错误输入是“无法找到DBD / mysql.pm”,而不是“无法找到DBD / Mysql.pm”)。
You also aren't setting the DSN as documented; 您也没有按照文档所述设置DSN。 it should be in one of these forms:
它应采用以下形式之一:
$dsn = "DBI:mysql:$database";
$dsn = "DBI:mysql:database=$database;host=$hostname";
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
Also, you will save yourself a lot of headaches in the future if you always say: 另外,如果您总是说:将来,您会为自己省去很多麻烦:
use 5.018;
use warnings;
in your scripts and properly declare your variables. 在脚本中并正确声明变量。 (Optionally use a lower minimum version number, but if you specify a version less than 5.012, you will need to also
use strict;
since that won't be done for you.) ((可选)使用较低的最低版本号,但是如果您指定的版本小于5.012,则还需要
use strict;
因为这不会为您完成。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.