Code igniter prepending db prefix in table aliases

落爺英雄遲暮 提交于 2019-12-10 10:46:25

问题


I have configured code igniter to use db prefix.

At all other places it is working as expected but while creating table aliases it is prepending db prefix.

Code is as under:-

$this->db->from('table_a');
$this->db->join('table_b', 'table_a.id = table_b.a_id', 'left');
-----
$this->db->join('table_b as tablebAlias', 'table_c.id = tablebAlias.a_id', 'left');

Assuming my dbprefix is set to value 'foo'.

Final query which is getting executed is as under:-

Select * From foo_table_a left join foo_table_b on foo_table_a.id = foo_table_b.a_id
--- left join foo_table_b as tablebAlias on foo_table_c.id = foo_tablebAlias.a_id

Any help will be highly appreciable.

Thanks, Jatin


回答1:


I found out that manual queries ignore table prefix. I also found out that there is a way to add table prefix to manual queries:

In config/database.php

One can do this:

$db['default']['dbprefix'] = "feed_";  
$db['default']['swap_pre'] = "{PRE}";

So that this can be done:

$sql = "SELECT * FROM {PRE}item";  
$query = $this->db->query($sql); 

The {PRE} becomes feed_.

But swap_pre is not config.php which leads me to think that this is CI 2.0 feature.




回答2:


I think you should use the normal query to avoid dbprefix. Try to use $this->db->query('your query')



来源:https://stackoverflow.com/questions/10548950/code-igniter-prepending-db-prefix-in-table-aliases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!