首页 > 解决方案 > 如何将 INSTR 与 Kohana ORM 一起使用?

问题描述

我需要对使用 kohana 框架(版本 3.1.1.1)制作的一些旧系统进行更改,用户必须输入至少部分名称,系统必须输出结果。通常我使用 PHP,我可以很容易地做到这一点:

INSTR(my_table, 'some value') > 0 OR INSTR(my_other_table, 'some value') > 0

我看到了一些 kohana orm 语法,例如:

$temp = ORM::factory('table_name')->where('column1','=',$value1)->and_where('column2','=',$value2)->find();

但我不知道使用 kohana orm 实现我的 INSTR 查询的语法。有谁能够帮我?

谢谢你们。

标签: kohanakohana-3kohana-orminstr

解决方案


$temp = ORM::factory('table_name')->where('column1','=',$value1)->and_where('column2','=',$value2)->find()

是一种不好的做法,使用查询创建模型方法。

使用DB::expr()

 $expression = DB::expr('COUNT(users.id)');
 $query = DB::update('users')->set(array('login_count' => DB::expr('login_count + 1')))->where('id', '=', $id);
 $users = ORM::factory('user')->where(DB::expr("BINARY `hash`"), '=', $hash)->find();

推荐阅读