您好,欢迎访问一九零五行业门户网

CakePHP怎么写MySQL的IN条件

我的代码是这么写的
$ids = '1,2,3,4';$conditions[]=array('id in (?)'=> $ids);

拼出来的sql是
select ...ooxx... where id in ('1,2,3,4');

这条sql其实是错的,应该是
select ...ooxx... where id in (1,2,3,4);

我应该在代码里怎么写呢?
回复内容: 我的代码是这么写的
$ids = '1,2,3,4';$conditions[]=array('id in (?)'=> $ids);

拼出来的sql是
select ...ooxx... where id in ('1,2,3,4');

这条sql其实是错的,应该是
select ...ooxx... where id in (1,2,3,4);

我应该在代码里怎么写呢?
$conditions[] = array( 'id' => array(1, 2, 3, 4 ) );
可以通过在对应的字段名后面设置一个包含有值的数组来实现与sql逻辑运算符in()同等的效果。
久不用了 ... 在我记忆中直接传递数组即可 ...
示例如下 ...
$this->foo->find( 'all', array( 'conditions' => array( 'foo.bar' => array( 1, 2, 3, 4 ) )) );
其它类似信息

推荐信息