gpt4 book ai didi

mysql - 在表中添加 Codeigniter 数据库前缀

转载 作者:行者123 更新时间:2023-11-30 22:35:39 25 4
gpt4 key购买 nike

我有一个数据库,其中所有的表名如下所示

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

我之前需要表名后的前缀,但没有得到任何解决方案。

最佳答案

唯一的选择是更改驱动程序文件。您可以使用以下步骤执行此操作:

  1. 转到/system/database/DB_query_builder.php
  2. 搜索公共(public)函数dbprefix
  3. 替换

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com