Error while using PDO prepared statements and LIMIT in query [duplicate] Error while using PDO prepared statements and LIMIT in query [duplicate] php php

Error while using PDO prepared statements and LIMIT in query [duplicate]


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

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

Thanks Álvaro G. Vicario and Maerlyn


You can do like this:

$sql = SELECT * FROM tbl_news ORDER BY date DESC LIMIT :start, :rows";$q = $db->prepare($sql);$q->bindParam(':start', $start, PDO::PARAM_INT);$q->bindParam(':rows',$rows, PDO::PARAM_INT);


It is a known bug which was fixed in 5.5.6 from memory.

From the article:LIMIT doesn't allow variables in any context.Its arguments must be integer constants.

Further Edit: (There is contention on the matter)User variables are accepted arguments of LIMIT clause in prepared statements, and SQL syntax for prepared statements can be used in stored procedures.

Third Edit:This link explains that these should work with prepared statements.