How to pass an integer to a query in CakePHP?

六眼飞鱼酱① 提交于 2019-12-25 02:11:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!