提问人:Alan Alvarez 提问时间:8/17/2020 最后编辑:Alan Alvarez 更新时间:9/1/2020 访问量:33
如何将 INSTR 与 Kohana ORM 一起使用?
How to use INSTR with 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 查询的语法。 谁能帮我?
谢谢大家。
答:
1赞
WinterSilence
9/1/2020
#1
$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();
评论