gpt4 book ai didi

PHP PDO 未正确绑定(bind)

转载 作者:行者123 更新时间:2023-11-29 21:32:09 28 4
gpt4 key购买 nike

$conn = getConn();
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "select * from posts where fk_user_id in (select id_user_1 from contacts where id_user_2=:_id) or (select id_user_2 from contacts where id_user_1=:_id) or :_id order by date desc limit 15 offset :_offset";
$stmt = $conn->prepare($sql);
$stmt->bindParam('_id', $id);
$o = "0";
$stmt->bindParam('_offset', $o);

Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''0'' at line 1

由于某种原因,它没有正确绑定(bind)参数;如果我在 SQL 中手动输入 0,一切正常。

修复:我通过添加 PDO::PARAM_INT 修复了该问题。 $stmt->bindParam(':_offset', $offset, PDO::PARAM_INT);

最佳答案

您绑定(bind)的参数不正确。应该是:

$stmt->bindParam(':_id', $id);
$offset = 0;
$stmt->bindParam(':_offset', $offset, PDO::PARAM_INT);

关于PHP PDO 未正确绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171546/

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