-2

好像我做不到。基本上,使用了三个 PHP 文件: - login.php、testconnect.php 和 numrows.php numrows.php 是第一次开始播放的主要文件。

login.php 和 testconnect.php 都不错。

numrows.php:-

<?php
global $dbh1;
require_once "testconnect.php";

try
    {  
    $stmt = $dbh1->prepare("select count(distinct mfg_code) from test");
    $stmt->execute();
}

catch(PDOException $err)
{
    $alertmsg = $err->getMessage();
    }

$num = $stmt->fetch("PDO::FETCH_ASSOC:");
$num = json_encode($num);

echo $num;
?>

来自 apache 的日志错误显示“”GET /testnumcards.php HTTP/1.1“500 -”。我在调试时遇到的错误再次是“NetworkError:500 Internal Server Error”。正确的做法是什么?

4

1 回答 1

2

您的问题不是使 $dbh 可用,而是代码不一致和语法错误。
至少以这种方式制作你的文件,没有所有无用和错误的代码

<?php
require_once "testconnect.php";
$stmt = $dbh1->prepare("select count(distinct mfg_code) from test");
$stmt->execute();
$num = $stmt->fetch(PDO::FETCH_ASSOC); // note the proper syntax
$num = json_encode($num);
echo $num;

然后查看 error_log 以获取详细信息

于 2013-07-22T09:18:54.307 回答