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

查看:80
本文介绍了在使用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''

推荐答案

关于发布

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

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

感谢ÁlvaroG. Vicario Maerlyn

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

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