如何在CakePHP中将整数传递给查询? [英] How to pass an integer to a query in CakePHP?

查看:70
本文介绍了如何在CakePHP中将整数传递给查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是与LIMIT无关,这是关于传递整数.需要传递数字的其他函数是 IN

Edit 1: this is not about LIMIT , this is about passing an integer. Other function that requires to pass numbers is IN

我应该使用PDO :: PARAM_INT吗?

Edit 2: Should I use PDO::PARAM_INT ?

当我这样做时:

$query .=  ' LIMIT ? , ? ';
$values [] =  $offset ;
$values [] = $rows ;

在这一行:

$db->fetchAll ( $query ,   $values);

代替执行:

SELECT .......  LIMIT 0 ,  10;

它试图执行:

SELECT .......  LIMIT '0' ,  '10';

引起错误:错误代码:1064.检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在``0','10''

注意1.我知道限制在$ params数组中..

注释2.有一个与这里

注3.我已经尝试过:$values [] = intval($offset)$values [] = (int)$offset,甚至是一个整数,例如:$values [] = 10

Note 3. I have tried: $values [] = intval($offset), $values [] = (int)$offset, and even an integer like: $values [] = 10

推荐答案

我不喜欢Cake,但在PDO中,您应该同时使用 intval-PDO::PARAM_INT-它们都不能单独使用.

I dunno about Cake but in PDO you should use both intval and PDO::PARAM_INT- none of them would do separately.

在我的PDO包装器中,此问题已得到解决,可以使第一个代码正确运行,但是我怀疑您是否会为自己的框架实施该代码

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

这篇关于如何在CakePHP中将整数传递给查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆