为什么我的 Perl CGI 抱怨“无法找到 Mysql.pm”?

发布于 2024-08-26 00:52:11 字数 1182 浏览 4 评论 0原文

我有两个文件夹 phpperl。它们分别包含 index.phpindex.pl

我的 Perl 代码如下所示:

#!/usr/bin/perl
use Mysql;

print "Content-type: text/html\n\n"; 
print "<h2>PERL-mySQL Connect</h2>";
print "page info";
$host = "localhost";
$database = "cdcol";
$user = "root";
$password = "";
$db = Mysql->connect($host, $database, $user, $password);
$db->selectdb($database);

当我运行上面的代码时(通过在浏览器中输入 http://localhost:88/perl/),我收到以下错误:

Can't located Mysql @INC 中的 .pm(@INC 包含:C:/xampp/perl/site/lib/ C:/xampp/perl/lib C:/xampp/perl/site/lib C:/xampp/apache)位于 C:/ xampp/htdocs/perl/index.pl 第 2 行。 BEGIN 失败 - 编译在 C:/xampp/htdocs/perl/index.pl 第 2 行中止。

浏览到 http://localhost: 88/php/ 有效。

index.php 有:

<?php
$con = mysql_connect("localhost","root","");
    if($con)
    {
        if(mysql_select_db("cdcol", $con))
        {
            $sql="SELECT Id From products";
            if(mysql_query($sql))
            {
                $result = mysql_query($sql);
                if ($result) ...

I have two folders php and perl. They contain index.php and index.pl, respectively.

My Perl code looks like:

#!/usr/bin/perl
use Mysql;

print "Content-type: text/html\n\n"; 
print "<h2>PERL-mySQL Connect</h2>";
print "page info";
$host = "localhost";
$database = "cdcol";
$user = "root";
$password = "";
$db = Mysql->connect($host, $database, $user, $password);
$db->selectdb($database);

When i run above code (by typing http://localhost:88/perl/ in the browser), I get the following error:

Can't locate Mysql.pm in @INC (@INC contains: C:/xampp/perl/site/lib/ C:/xampp/perl/lib C:/xampp/perl/site/lib C:/xampp/apache) at C:/xampp/htdocs/perl/index.pl line 2. BEGIN failed--compilation aborted at C:/xampp/htdocs/perl/index.pl line 2.

whereas browsing to http://localhost:88/php/ works.

index.php has:

<?php
$con = mysql_connect("localhost","root","");
    if($con)
    {
        if(mysql_select_db("cdcol", $con))
        {
            $sql="SELECT Id From products";
            if(mysql_query($sql))
            {
                $result = mysql_query($sql);
                if ($result) ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像你 2024-09-02 00:52:11

您应该将 DBIDBD::mysql

您应该使用标准 CGI 处理模块,例如 CGI::Simple

use strict; use warnings;
use CGI::Simple;
use DBI;

my $cgi = CGI::Simple->new;
my $dsn = sprintf(
    'DBI:mysql:database=%s;host=%s',
    'cdcol', 'localhost'
);

my $dbh = DBI->connect($dsn, root => '',
    { AutoCommit => 0, RaiseError => 0 }
);

my $status = $dbh ? 'Connected' : 'Failed to connect';

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>$status</p>
</body>
</html>
HTML

You should use DBI in conjunction with DBD::mysql.

You should use a standard CGI processing module such as CGI::Simple.

use strict; use warnings;
use CGI::Simple;
use DBI;

my $cgi = CGI::Simple->new;
my $dsn = sprintf(
    'DBI:mysql:database=%s;host=%s',
    'cdcol', 'localhost'
);

my $dbh = DBI->connect($dsn, root => '',
    { AutoCommit => 0, RaiseError => 0 }
);

my $status = $dbh ? 'Connected' : 'Failed to connect';

print $cgi->header, <<HTML;
<!DOCTYPE HTML>
<html>
<head><title>Test</title></head>
<body>
<h1>Perl CGI Script</h1>
<p>$status</p>
</body>
</html>
HTML
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文