更新
为了尝试简化问题,我制作了以下文件(dbtest.pl)
#!/usr/bin/perl
use DBI;
use DBD::mysql;
print "Content-type: text/html \n\n";
print "hi";
我希望它能加载页面然后说“嗨”。但是,它给了我一个来自wordpress的404错误。这只是一个使用DBD :: mysql有问题的情况吗?是不是我的服务器上没有正确安装?
原帖
直到最近,我有一些简单的perl工作,一旦完成交易,就将数据库列更新为“已处理”。
出于某种原因,这已停止工作。起初我认为这与运行网站root和mod_rewrite的wordpress安装有关,因为当我尝试直接访问pl时,它将我重新路由到wordpress 404页面。
然而,当我开始使用基本的perl'print'hello world'类型消息进行测试时,一切似乎都有效。
似乎当我包含'use DBD :: mysql;'这一行时该页面将重定向到404.如果我删除该行,则以下代码有效(直到它尝试访问数据库为止)。
如果有人在下面的代码中看到错误,或者有关于如何解决问题的建议,我们将不胜感激! (另外,如果我需要改进这个问题,请告诉我)
#!/usr/bin/perl
# PERL MODULES WE WILL BE USING
use DBI;
use DBD::mysql;
use CGI;
use MIME::Lite;
use Email::Valid;
use HTML::Entities ();
use CGI qw/:standard/;
$ok_chars = 'a-zA-Z0-9 ,-@';
$messageclean = "";
foreach $param_name ( param() ) {
$_ = HTML::Entities::decode( param($param_name) );
$_ =~ s/[^$ok_chars]//go;
param($param_name,$_);
}
local $query = new CGI;
# read in the cgi fields.
local $input_payment_reference = $query->param('payment_reference');
local $input_email = $query->param('Your_Email');
local $reference = $query->param('Transaction_ID');
# the reference is the last couple of digits, without the first 2 characters
$input_payment_reference = substr($reference, 2);
$msg = MIME::Lite->new(
To =>$input_email,
From =>'admin@admin.com',
Subject =>'Message',
Type =>'multipart/related'
);
$msg->attach(Type => 'text/html',
Data => qq{
<html>
<body>
<table rules="all" style="border-color: #666;" cellpadding="10">
<tr><td style="background: #eee;"><strong>Transaction ID:</strong> </td><td style="background:#fff;"> $input_payment_reference </td></tr>
</table>
<p>Thank you for registering</p>
</body>
</html>
}
);
# HTTP HEADER
print "Content-type: text/html \n\n";
# CONFIG VARIABLES
$platform = "mysql";
$database = "database";
$host = "localhost";
$port = "3306";
$tablename = "table";
$user = "user";
$pw = "password";
# DATA SOURCE NAME
$dsn = "dbi:$platform:$database:$host:$port";
# PERL DBI CONNECT
$connect = DBI->connect($dsn, $user, $pw) or die "Can't connect to the DB: $DBI::errstr\n";
# PREPARE THE QUERY
$query = "UPDATE $tablename SET orderStatus = 'processed'
WHERE transactionID = '".$input_payment_reference."'";
$query_handle = $connect->prepare($query);
# EXECUTE THE QUERY
$query_handle->execute();
# SEND EMAIL
$msg->send();