windows下 perl 连接 mysql
{我想在windows环境下编写perl程序和使用mysql,怎么做?悬赏分:10-提问时间2009-5-1308:17谁能告诉我,安装了perl已经,可mysql怎么弄...
{我想在windows环境下编写perl程序和使用mysql,怎么做?
悬赏分:10 - 提问时间2009-5-13 08:17
谁能告诉我,安装了perl已经,可mysql怎么弄~~怎么运行啊 }
解决了吗?该怎么一步一步弄啊?讨教……谢谢!
winXP cmd:
shell> perl -MCPAN -e shell
................ #ok
cpan> install DBI
................ #ok
cpan> install DBD::mysql
Set up gcc environment - 3.4.5 (mingw-vista special r3)
D:\MySQL\bin\MYSQLA~1.EXE: connect to server at 'localhost' failed
error: 'Access denied for user 'ODBC'@'localhost' (using password: NO)'
Problem running D:\MySQL\bin\MYSQLA~1.EXE - aborting ...
Warning: No success on command[C:\usr\bin\perl.exe Makefile.PL INSTALLDIRS=site]
CAPTTOFU/DBD-mysql-4.013.tar.gz
C:\usr\bin\perl.exe Makefile.PL INSTALLDIRS=site -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Failed during this command:
CAPTTOFU/DBD-mysql-4.013.tar.gz : writemakefile NO 'C:\usr\bin\per
l.exe Makefile.PL INSTALLDIRS=site' returned status 256
==============================================
求解…… 展开
悬赏分:10 - 提问时间2009-5-13 08:17
谁能告诉我,安装了perl已经,可mysql怎么弄~~怎么运行啊 }
解决了吗?该怎么一步一步弄啊?讨教……谢谢!
winXP cmd:
shell> perl -MCPAN -e shell
................ #ok
cpan> install DBI
................ #ok
cpan> install DBD::mysql
Set up gcc environment - 3.4.5 (mingw-vista special r3)
D:\MySQL\bin\MYSQLA~1.EXE: connect to server at 'localhost' failed
error: 'Access denied for user 'ODBC'@'localhost' (using password: NO)'
Problem running D:\MySQL\bin\MYSQLA~1.EXE - aborting ...
Warning: No success on command[C:\usr\bin\perl.exe Makefile.PL INSTALLDIRS=site]
CAPTTOFU/DBD-mysql-4.013.tar.gz
C:\usr\bin\perl.exe Makefile.PL INSTALLDIRS=site -- NOT OK
Running make test
Make had some problems, won't test
Running make install
Make had some problems, won't install
Failed during this command:
CAPTTOFU/DBD-mysql-4.013.tar.gz : writemakefile NO 'C:\usr\bin\per
l.exe Makefile.PL INSTALLDIRS=site' returned status 256
==============================================
求解…… 展开
5个回答
展开全部
先在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;
}
安装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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
开始-运行-cmd
输入 ppm install DBD::mysql
输入 ppm install DBD::mysql
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#
# Don't be stupid
# DBI comes by default with ActiveState_Perl
#
#/usr/bin/perl -w
use strict;
use DBI;
my $DSN = "DBI:mysql:Database;host=localhost";
my $dbh = DBI->connect($DSN, "UserName", "passwd",
{ PrintError => 0,
RaiseError => 1
} );
# Don't be stupid
# DBI comes by default with ActiveState_Perl
#
#/usr/bin/perl -w
use strict;
use DBI;
my $DSN = "DBI:mysql:Database;host=localhost";
my $dbh = DBI->connect($DSN, "UserName", "passwd",
{ PrintError => 0,
RaiseError => 1
} );
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
装xampp吧,然后再装active perl
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-03-10
展开全部
windows下安装perl模块不是用的ppm吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询