php - 如何在 codeigniter 中构建事件记录查询?

标签 php codeigniter activerecord

我最近开始将 codeigniter 应用程序中的后端查询转换为事件记录模式。截至目前,我正在使用 codeigniter 2.1 版本。我最初在 mysql 中编写了一个查询作为

SELECT * FROM table WHERE (field1 = $field1 OR field2 = $field2) AND field3 = $field3 AND field4 = 'text'

现在我想用下面给出的方式写这个东西:

$this->db->select('*');
$this->db->from('table');
$this->db->where('field1',$field1);
$this->db->or_where('field2',$field1);
$this->db->where('field3',$field2);
$this->db->where('field4','text');

但不知何故“or_where”函数无法正常工作。我很乐意为此提供任何解决方案?

最佳答案

您在 Active Record 中编写自定义字符串

$where = "(field1 = " . $field1 . " OR field2 = " . $field2 . ") AND 
          field3 = ". $field3 . " AND field4 = 'text'";
$this->db->where($where);

Click here for source: Active Record (and browse for custom string)

关于php - 如何在 codeigniter 中构建事件记录查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986257/

相关文章:

php - 在 codeigniter 中使用赋值运算符时出现错误结果

mysql - 每组最大 n 个 rails ActiveRecord SQL

php - MySQL : search function into a aggregated column by "group by"

php - AJAX 在脚本结束前停止执行

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

javascript - 分钟操作后 Momentjs 返回错误的日期

php - 从数据库中获取匹配的短语

php - linux (centos) 复制文件的权限

ruby-on-rails - 非持久 ActiveRecord 模型属性

ruby-on-rails - 如何使用 rspec 测试条件 ActiveRecord after_update 回调?