MySql一般错误:2053 [英] MySql General error: 2053
问题描述
我收到错误讯息:
错误:SQLSTATE [HY000]:一般错误:2053
ERROR: SQLSTATE[HY000]: General error: 2053
我不知道为什么会发生这种情况,因为代码运行正常,数据库更新,但仍然返回此错误。
I have no idea why this is happening because the code works fine and the database is updated, but it still returns this error.
这是我的代码:
<?php
header("Content-Type: application/json; charset=UTF-8");
require 'UHCauth.php';
try {
$conn = new PDO("mysql:host=$mysql_serv;dbname=$mysql_db", $mysql_user, $mysql_pass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
if(isset($_GET['d6518e47'])) {
$USERNAME = $_GET['d6518e47'];
$stmt = $conn->prepare(
"UPDATE $mysql_table
SET KILLS = KILLS+1 WHERE USERNAME = :USERNAME"
);
$stmt->execute(array('USERNAME' => $USERNAME));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode($row);
} else {
$stmt = $conn->prepare(
"SELECT * FROM $mysql_table
ORDER BY
McVersion DESC,
ModVersion DESC
LIMIT 1"
);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode($row);
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
推荐答案
$ row = $ stmt - > fetch(PDO :: FETCH_ASSOC);
是会导致错误的行。
为什么?
因为在更新之后没有任何内容可以获取 -
Because there's nothing to fetch - in array - after an update
请记住
PDO :: FETCH_ASSOC:返回一个按照返回的列名索引的数组
在结果集中
PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set
所以,没有结果集...没有方
So, no result set ... no party
如果你想知道你的命令的退出状态,只需使用 execute()
function
If you want to know exit status of your command, just use the return value of execute()
function
$ rv = $ stmt-& => $ USERNAME));
这篇关于MySql一般错误:2053的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!