问题
Edit 1: this is not about LIMIT , this is about passing an integer. Other function that requires to pass numbers is IN
Edit 2: Should I use PDO::PARAM_INT ?
When I do this:
$query .= ' LIMIT ? , ? ';
$values [] = $offset ;
$values [] = $rows ;
At this line:
$db->fetchAll ( $query , $values);
Instead of execute:
SELECT ....... LIMIT 0 , 10;
It tries to execute:
SELECT ....... LIMIT '0' , '10';
Causing an error: Error Code: 1064. 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 ''0' ,'10''
Note 1. I know that there is an option for limit in the $params array..
Note 2. There is a question related here
Note 3. I have tried: $values [] = intval($offset), $values [] = (int)$offset, and even an integer like: $values [] = 10
回答1:
I dunno about Cake but in PDO you should use both intval and PDO::PARAM_INT- none of them would do separately.
In my PDO wrapper I have this issue fixed, allowing first code to run without errors, but I doubt you would bother with implementing it for your framework
来源:https://stackoverflow.com/questions/22622062/how-to-pass-an-integer-to-a-query-in-cakephp