添加表前缀以在Codeigniter中加入 [英] Adding table prefix to join in Codeigniter
本文介绍了添加表前缀以在Codeigniter中加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有Codeigniter设置添加前缀kms_到我的活动记录查询。但是,我试图做一个加入两个ON条件,它不预先添加。
I have Codeigniter setup to add the prefix kms_ to my active record queries. However, I am trying to do a join with two ON conditions and it doesn't prepend them.
现在我必须手动添加它们,如:
Right now I have to manually add them like so:
$this->db->join('site_items', 'kms_site_items.item_id = kms_items.id AND kms_site_items.site_id = 1', 'left');
我可以不同的写法,以便正确添加表前缀吗?
Can I write this differently so that the table prefixes are added correctly?
有办法让这样的工作:
$this->db->join('site_items', 'site_items.item_id = items.id AND site_items.site_id = 1', 'left');
推荐答案
您可以手动获取当前数据库前缀:
You can get the current database prefix manually like this:
$prefixed_tablename = $this->db->dbprefix('tablename');
所以你可以这样做:
$this->db->join('site_items', $this->db->dbprefix('site_items') . '.item_id = ' . $this->db->dbprefix('items') . '.id AND ' . $this->db->dbprefix('site_items') . '.site_id = 1', 'left');
这篇关于添加表前缀以在Codeigniter中加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文