简体   繁体   English

使用Kohana ORM查询IN(2,3,4)

[英]Query IN (2,3,4) with Kohana ORM

I'm tying to do the following mysql with Kohana ORM: 我想和Kohana ORM一起做以下的mysql:

SELECT column_id FROM tables WHERE column_id IN (2, 3, 6)

How do I do this? 我该怎么做呢?

You can use the following syntax in kohana ORM: 您可以在kohana ORM中使用以下语法:

in()

Creates an IN portion of a query. 创建查询的IN部分。
It has three parameters: 它具有三个参数:
1.the column to match 1.匹配的列
2.an array or string of values to match against (boolean), 2.要与(布尔值)相匹配的数组或值字符串,
3. to create a NOT clause instead 3.改为创建NOT子句

$db->in('title', array(1,2,3,4,5));

This generates: title IN ('1','2','3','4','5') 这会产生: title IN ('1','2','3','4','5')

If tables is the name of your table, try something like 如果tablestables的名称,请尝试类似的方法

$rows = ORM::factory('tables')->in('column_id', array(2, 3, 6))->find_all();


Since in() is failing for you through the ORM, this should work in the interim: 由于in()无法通过ORM为您服务,因此这应该在此期间起作用:

$rows = DB::select()->from('tables')->where('column_id', 'IN', array(2, 3, 6));

Ended up using: 最终使用:

->and_where('column_id', 'in', $args())

Decided to stick with ORM db methods instead of kohana's database query builders. 决定坚持使用ORM db方法,而不是kohana的数据库查询构建器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM