What docs have to say: LIMIT子句可用于限制行数 SELECT语句返回的值. LIMIT取一或两个数字 参数,都必须都是非负整数常量,并带有 这些例外: The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions: 在准备好的语句中,可以使用?指定LIMIT参数.占位符标记. Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.在存储的程序中,可以使用整数值的例程参数或局部变量来指定LIMIT参数.Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.您的选择包括: 一个个地绑定参数,以便您可以设置类型:Bind parameters one by one so you can set a type:$comments->bindParam(1, $post, PDO::PARAM_STR);$comments->bindParam(2, $min, PDO::PARAM_INT);$comments->bindParam(3, $min, PDO::PARAM_INT); 请勿将这些值作为参数传递Do not pass those values as parameters:$query = sprintf('SELECT id, content, date FROM comment WHERE post = ? ORDER BY date DESC LIMIT %d, %d', $min, $max); 禁用模拟准备(MySQL驱动程序具有一个错误/功能,会使它引用数字参数):Disable emulated prepares (the MySQL driver has a bug/feature that will make it quote numeric arguments):$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); 这篇关于带预备语句的MySQL上的LIMIT关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 00:29