问题描述
我需要对使用框架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查询的。 有人可以帮我吗?
谢谢大家。
解决方法
$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();