Codeigniter activerecord JOIN和表名别名问题

时间:2018-01-11 19:46:12

标签: php mysql codeigniter activerecord

我需要有关特定codeigniter 3.1.6活动记录查询的帮助,以便不断返回错误。

代码本身是:

$this->db->select('ms_payments.id, ms_payments.user_id, ms_payments.memberships_user_id, ms_payments.staff_id, ms_payments.rate_amount, ms_payments.tax, ms_payments.coupon, ms_payments.total, ms_payments.currency, ms_payments.pp, ms_payments.date,
u1.first_name AS user_name, u1.last_name AS user_last_name, u2.first_name AS staff_name, u2.last_name AS staff_last_name, 
ms_gateways.displayname AS pp, ms_memberships_users.id, ms_memberships.title AS membership')
      ->from('ms_payments')

      ->join('auth_users as u1', 'u1.id = ms_payments.user_id') 
      ->join('auth_users as u2', 'u2.id = ms_payments.staff_id') 

      ->join($this->gTable, 'ms_gateways.id = ms_payments.pp') 
      ->join($this->muTable, 'ms_memberships_users.id = ms_payments.memberships_user_id')
      ->join($this->mTable, 'ms_memberships.id = ms_memberships_users.membership_id')

      ->where('ms_payments.box_id =', $this->box_id);

$result = $this->db->get()->result();

问题与前两个连接有关,我怀疑是因为表名别名。

$ this-> db-> get_compiled_select()查询生成的SQL查询完美运行:

SELECT `ms_payments`.`id`, `ms_payments`.`user_id`, `ms_payments`.`memberships_user_id`, `ms_payments`.`staff_id`, `ms_payments`.`rate_amount`, `ms_payments`.`tax`, `ms_payments`.`coupon`, `ms_payments`.`total`, `ms_payments`.`currency`, `ms_payments`.`pp`, `ms_payments`.`date`, 
`u1`.`first_name` AS `user_name`, `u1`.`last_name` AS `user_last_name`, `u2`.`first_name` AS `staff_name`, `u2`.`last_name` AS `staff_last_name`, `ms_gateways`.`displayname` AS `pp`, 
`ms_memberships_users`.`id`, `ms_memberships`.`title` AS `membership`

FROM `ms_payments`

JOIN `auth_users` as `u1` ON `u1`.`id` = `ms_payments`.`user_id`
JOIN `auth_users` as `u2` ON `u2`.`id` = `ms_payments`.`staff_id`

JOIN `ms_gateways` ON `ms_gateways`.`id` = `ms_payments`.`pp`
JOIN `ms_memberships_users` ON `ms_memberships_users`.`id` = `ms_payments`.`memberships_user_id`
JOIN `ms_memberships` ON `ms_memberships`.`id` = `ms_memberships_users`.`membership_id`

WHERE `ms_payments`.`box_id` = '1'

然而我仍然得到这个codeigniter错误,任何线索为什么?

  

Blockquote遇到未被捕获的异常   Blockquote类型:错误
  Blockquote消息:在布尔值

上调用成员函数result()

0 个答案:

没有答案