kohana - 如何将 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 查询的语法。有谁能够帮我?
谢谢你们。
解决方案
$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();
推荐阅读
- react-navigation - 将 react-navigation 从 4.x 升级到 5.1 后,初始组件屏幕不会路由
- node.js - 如何从 mongodb 中的聚合中获取数据结果和计数
- android - 在 android studio 中更改密码,使用 firebase firestore 作为数据库
- reactjs - 如何删除 Material-UI 的网格行之间的不必要空间?
- kubernetes - --default-unreachable-toleration-seconds 和 --default-not-ready-toleration-seconds 不起作用
- javascript - 当它被写在 javascript 的函数中时,我得到了未定义。为什么会这样
- amazon-web-services - 无法从 API 网关向 SNS 主题发送大负载
- c++ - 不能在另一个类中的迭代器类中制作 operator<<
- python - 编辑管理首页的模板
- reactjs - 反应中具有布尔值的useState