为什么我的Perl CGI抱怨“找不到Mysql.pm”? [英] Why does my Perl CGI complain "Can't locate Mysql.pm"?

查看:89
本文介绍了为什么我的Perl CGI抱怨“找不到Mysql.pm”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的Perl代码如下:

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);

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

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

在以下位置找不到Mysql.pm @INC(@INC包含:C:/ xampp / htdocs中的C:/ xampp / perl / site / lib / C:/ xampp / perl / lib C:/ xampp / perl / site / lib C:/ xampp / apache) /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) ...


推荐答案

您应将 DBI DBD :: mysql

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

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

这篇关于为什么我的Perl CGI抱怨“找不到Mysql.pm”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆