【发布时间】:2014-04-05 02:45:03
【问题描述】:
我的查询
$stmt = $db->prepare('SELECT * FROM generalevent ORDER BY date DESC LIMIT ?, 25');
$stmt->execute(array( $limit ));
消息一直失败
exception 'PDOException' with message '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 '?, 25' at line 1'
in ../test.php:35
Stack trace: #0 ../test.php(35): PDO->prepare('SELECT * FROM g...') #1 {main}
我已经有了
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
所以根据我的阅读,这应该可以,不是吗?
【问题讨论】:
-
$limit是如何定义的? -
@Fred-ii-
$limit = $currPage*25;它的类型是integer,我检查了gettype。 -
@PatrickQ 仅供参考:
date不是保留字。 -
@gta0004 你可以试试
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);或DESC LIMIT %d, 25'