php - Codeigniter 如何一起使用 get_where/or_where 来返回一个 result_array

标签 php mysql codeigniter

我正在尝试从数据库中获取一个 result_array(),其中两列必须返回 true,反之亦然,所以我决定使用 or_where 但我的代码是返回 Call to undefined method CI_DB_mysqli_result::or_where() 错误,任何建议如何实现这个?

我在 CI_Model 中使用以下代码。

public function check_request($userid, $senderid){
     $query = $this->db->get_where('connection',array('user_id' => $userid, 'sender_id' => $senderid));
     $query = $this->db->or_where('connection',array('sender_id' => $userid, 'user_id' => $senderid));
     return $query->result_array();
}

最佳答案

试试下面的方法:

public function check_request($userid, $senderid){
   $this->db->select('*');
   $this->db->where("(user_id = '$userid' AND sender_id = '$senderid') 
               OR (sender_id='$userid' AND user_id = '$senderid')");
   $query = $this->db->get('connection');
   return $query->result_array();
}

关于php - Codeigniter 如何一起使用 get_where/or_where 来返回一个 result_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45318215/

相关文章:

php - 使用 mysqli 准备时如何查看 MYSQL 执行状态?

php - '数据库错误 : Unable to connect to the database:Could not connect to MySQL' in Joomla

php - 删除 codeigniter 2.1.0 中的 index.php

php - 显示 PHP 表中的最新年份

javascript - 我有一个 div,它需要动态复制

php - 需要知道要在 codeigniter 中执行哪个查询

php - 尝试修改 codeigniter 应用程序数据库表中的字段,但知道如何识别该表

php - 在没有 root 的情况下安装 PHP LDAP 模块

php - 如何使用 PHP 邮件程序脚本获取电子邮件 header 中的密件抄送信息

php - CodeIgniter View 中应包含多少代码?