我有一个数据库,其中所有的表名如下所示
configuration_dst,
developer_dst,
application_dst
现在我想管理我的查询,希望在表名之后而不是之前添加数据库前缀。 例如:
{TABLE NAME}{PREFIX}
是否可以使用 CI 3.0 进行管理?
我在 Application/configuration/database.php 中尝试过如下所示
$db['default']['dbprefix']="_dst";
$db['default']['swap_pre']="{POST}";
当前查询:
$this->db->get('templates');
当前表名:
tablename : _dsttemplates
预期表名称:
tablename : templates_dst
我之前需要表名后的前缀,但没有得到任何解决方案。
最佳答案
唯一的选择是更改驱动程序文件。您可以使用以下步骤执行此操作:
- 转到
/system/database/DB_query_builder.php
- 搜索
公共(public)函数dbprefix
替换
return $this->dbprefix.$table;
与
return $table.$this->dbprefix;
如果它还干扰了您项目中的任何其他地方,则使用替换代码创建一个新函数,例如:
public function dbsuffix($table = '')
{
if ($table === '')
{
$this->display_error('db_table_name_required');
}
return $table.$this->dbprefix;
}
关于mysql - 在表中添加 Codeigniter 数据库前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32622717/