【发布时间】:2016-02-08 17:08:09
【问题描述】:
我遇到了一件很奇怪的事情。
这会引发 500 服务器错误:
function writeMsg() {
$id='0000000625';
$translation = 'word';
try {
$stmt = $conn->prepare("UPDATE table SET HUN=? WHERE ID=?");
$stmt->execute(array($translation,$id));
$response["success"] = 1;
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
$response["success"] = 0;
}
echo 'RESPONSE: '.$response["success"];
}
writeMsg();
运行良好:
$id='0000000625';
$translation = 'word';
try {
$stmt = $conn->prepare("UPDATE table SET HUN=? WHERE ID=?");
$stmt->execute(array($translation,$id));
$response["success"] = 1;
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
$response["success"] = 0;
}
echo 'RESPONSE: '.$response["success"];
我只删除了第一行和最后两行。 有人对此有解释吗?
【问题讨论】:
-
请告诉我们
$conn的定义位置 -
是的,可能需要一个 - global $conn;
-
只需在你的函数中添加
global $conn; -
我很确定这是 $conn 的事情。我马上回来。