在查询中使用 PDO 准备好的语句和 LIMIT 时出错 [英] Error while using PDO prepared statements and LIMIT in query

查看:34
本文介绍了在查询中使用 PDO 准备好的语句和 LIMIT 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 PDO.但是,当我在包含 LIMIT 的查询中使用准备好的语句时,我遇到了问题.有什么问题?
代码:

I'm using PDO in my application. But I have a problem while I'm working with prepared statements in a query that contains LIMIT. What's the problem?
Codes:

$start = 0;
$rows = 20;
$sql = "SELECT * FROM tbl_news ORDER BY date DESC LIMIT ?, ?";
$q = $db->prepare($sql);
$q->execute(array($start , $rows));

错误:

检查与您的 MySQL 服务器版本相对应的手册,了解在0"、20"附近使用的正确语法

check the manual that corresponds to your MySQL server version for the right syntax to use near ''0', '20''

推荐答案

关于发布 带有准备语句的 MySQL 上的 LIMIT 关键字 ,下面的代码可以解决我的问题.

Regarding to post LIMIT keyword on MySQL with prepared statement , the code below could solve my problem.

$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);

感谢 Álvaro G. VicarioMaerlyn

这篇关于在查询中使用 PDO 准备好的语句和 LIMIT 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆