Adding table prefix to join in Codeigniter

后端 未结 2 1152
耶瑟儿~
耶瑟儿~ 2021-01-17 01:02

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.

R

相关标签:
2条回答
  • 2021-01-17 01:28

    You can get the current database prefix manually like this:

    $prefixed_tablename = $this->db->dbprefix('tablename');
    

    So you could do this:

    $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');
    

    Docs Here

    0 讨论(0)
  • 2021-01-17 01:46

    You can simply add Prefix table name like this :
    for example your tables have myPrefix_ as prefix and one of them might be myprefix_user.
    After that in your config/database.php at the bottom of this page where you set your database name, username and password, You can see dbprefix and you can set your prefix as I mentioned above myPrefix_.
    At the end, You can simply call your table name for example $this->db->get('user') and automatically Codeigniter set your prefix at the first of it.

    0 讨论(0)
提交回复
热议问题