我遇到了一个 PDO 问题,我已经看到了这个问题,但提供的不同解决方案对我不起作用。它是在绑定一个数字来设置 SQL 查询的 LIMIT 时。
这是我得到的错误:
Warning: PDOStatement::execute(): 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 ''2'' at line 1 in ...
编码:
$remaining = 3 - $countRows;
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$result4 = $con->prepare("SELECT * FROM item_descr WHERE id_item != ? LIMIT ?");
$result4->execute(array($itemId, intval($remaining)));