disucz 多实例数据库 代码调用 。
成功案例基于 discuz 2.5
修改 conf/config_global.php
1
2
3
4
5
6
7
8
9
|
//新增数据库配置信息
$_config[‘db‘][‘2‘][‘dbhost‘] =‘192.168.1.2‘;
$_config[‘db‘][‘2‘][‘dbuser‘] =‘root‘;
$_config[‘db‘][‘2‘][‘dbpw‘] =‘123‘;
$_config[‘db‘][‘2‘][‘dbcharset‘] =‘utf8‘;
$_config[‘db‘][‘2‘][‘pconnect‘] =‘0‘;
$_config[‘db‘][‘2‘][‘dbname‘] =‘op‘;
$_config[‘db‘][‘2‘][‘tablepre‘] =‘op_‘;
|
修改 source/class/class_core.php
1
2
|
//最下面一行 增加
classDB_BIextendsdiscuz_database{}
|
复制 soucrce/class/db_driver_mysql.php
成 db_driver_mysql_bi.php
修改 db_driver_mysql_bi.php 中
1
2
3
4
5
6
|
//修改class名字
classdb_driver_mysql_bi.php
//修改读取配置文件的序列号
$this->tablepre =$config[‘2‘][‘tablepre‘];
//设置connect的标识信息
functionconnect($serverid= 2) {
|
引用新的数据库代码操作实例
1
2
3
4
5
6
7
|
$driver=‘db_driver_mysql_op‘;
$_config=array();
@includeDISCUZ_ROOT.‘./config/config_global.php‘;
DB_BI::init($driver,$_config[‘db‘]);
$userinfo= DB_BI::fetch_first("SELECT * FROM op_users");
var_dump($userinfo);
|
原文:http://www.cnblogs.com/fenle/p/4395467.html