表别名中的代码点火器之前的数据库前缀 [英] Code igniter prepending db prefix in table aliases

查看:52
本文介绍了表别名中的代码点火器之前的数据库前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将代码点火器配置为使用db前缀.

I have configured code igniter to use db prefix.

在所有其他地方,它都按预期工作,但是在创建表别名时,它以db前缀开头.

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

代码如下:-

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

假设我的dbprefix设置为值'foo'.

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.

谢谢,贾廷(Jatin)

Thanks, Jatin

推荐答案

我发现手动查询会忽略表前缀.我还发现,有一种方法可以将表前缀添加到手动查询中:

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:

在config/database.php

In config/database.php

一个可以做到这一点:

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

这样可以做到:

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

{PRE}成为feed _.

The {PRE} becomes feed_.

但是swap_pre不是config.php,这使我认为这是CI 2.0功能.

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

这篇关于表别名中的代码点火器之前的数据库前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆