限制在带有变量的 SQL 语句中不起作用 [英] Limit not working in SQL statement with Variable
本文介绍了限制在带有变量的 SQL 语句中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用php为mysql数据库编写的以下语句总是给我带来错误您的SQL语法有误;请检查与您的MySQL服务器版本相对应的手册,以获取在''10''附近使用的正确语法在第 1 行'".
The following statement written in php for a mysql database always brings me the error "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 ''10'' at line 1'".
('SELECT `creator`,`created`,`content`
FROM mytable
WHERE `groupid`=?
ORDER BY `created` DESC
LIMIT ?', $foo, 10)
当我用数字替换问号时,它起作用了.
When I replace the questionmark with a number, it works.
我的错误在哪里?
推荐答案
您不能将数字绑定到 LIMIT .. 只需将其添加到实际查询中:
You can't bind number to the LIMIT .. just add it to the actual query:
('SELECT `creator`,`created`,`content`
FROM mytable
WHERE `groupid`=?
ORDER BY `created` DESC
LIMIT ' . 10, $foo)
这篇关于限制在带有变量的 SQL 语句中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文