Discuz DB层跨库映射关系表名前缀BUG修复后产生的新bug

本文介绍了一个由于逻辑引入导致的跨多库连接时出现表名前缀映射混乱的问题,并提供了一段用于修复该问题的 PHP 代码示例。通过调整数据库配置和映射设置,可以有效地解决表名前缀映射不一致的问题。

新的逻辑引入了新的bug,会导致在跨多库连接时,产生表名前缀映射混乱,需要再做逻辑上的修复。

 

 

function table_name($tablename) {
        if(!empty($this->map) && !empty($this->map[$tablename])) {
            $id = $this->map[$tablename];
            if(!empty($this->config[$id]['tablepre'])){
                $this->tablepre = $this->config[$id]['tablepre'];
            }
            if(!$this->link[$id]) {
                $this->connect($id);
            }
            $this->curlink = $this->link[$id];
        } else {
            $this->tablepre = $this->config['1']['tablepre'];
            $this->curlink = $this->link[1];
        }
        return $this->tablepre.$tablename;
    }

 

附db Map 写法:

$_config['db']['1']['dbhost'] = 'localhost'; // 服务器地址
$_config['db']['1']['dbuser'] = 'root'; // 用户
$_config['db']['1']['dbpw'] = 'root';// 密码
$_config['db']['1']['dbcharset'] = 'gbk';// 字符集
$_config['db']['1']['pconnect'] = '0';// 是否持续连接
$_config['db']['1']['dbname'] = 'x1';// 数据库
$_config['db']['1']['tablepre'] = 'pre_';// 表名前缀

$_config['db']['2']['dbhost'] = 'localhost';
.....

//再配置一些数据源
$_config['db']['xxx_sys']['dbhost'] = 'localhost';

//映射
$_config['db']['map']['yyy_table'] = 'xxx_sys';

 

上一篇文章:http://www.cnblogs.com/x3d/p/3913690.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值