gpt4 book ai didi

php - SQLSTATE[HY000] : General error: 1210 Incorrect arguments to mysqld_stmt_execute

转载 作者:行者123 更新时间:2023-11-29 03:24:23 31 4
gpt4 key购买 nike

下面的代码在共享主机上给了我这个错误,其中 db 中查看的表没有值

$query = "SELECT COUNT(*) FROM viewed WHERE memberID = :memberID";
$stmt = $db->prepare($query);
$stmt->bindParam(':memberID', $uid, PDO::PARAM_INT);
$stmt->execute();
$total = $stmt->fetchColumn();

$pages = ceil($total / $per_page);

$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
'options' => array(
'default' => 1,
'min_range' => 1,
),
)));

$offset = ($page - 1) * $per_page;

$query = "SELECT * FROM viewed WHERE memberID = :memberID ORDER BY id DESC LIMIT :per_page OFFSET :offset";

$stmt = $db->prepare($query);
$stmt->bindParam(':per_page', $per_page, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->bindParam(':memberID', $uid, PDO::PARAM_INT);
$stmt->execute();

$result = $stmt->fetchAll();

但是在我的配置文件中我删除了

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

然后错误消失但没有 PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION 我怎么知道错误?

谢谢

最佳答案

发生这种情况是因为您不需要在 limit 和 offset 中绑定(bind)变量。你应该只在where条件下使用绑定(bind)。你可以直接查询。见下文:

$query = "SELECT * FROM viewed WHERE memberID = :memberID ORDER BY id DESC LIMIT $per_page OFFSET $offset";

$stmt = $db->prepare($query);
$stmt->bindParam(':memberID', $uid, PDO::PARAM_INT);

关于php - SQLSTATE[HY000] : General error: 1210 Incorrect arguments to mysqld_stmt_execute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777515/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com