In Discuz! In x, you can easily use multiple databases and configure different database connections separately. The following two benefits are provided in the estimation. 1. if the load is sufficient, some tables can be distributed across multiple database servers. In this way, the load is reduced. 2. data in other databases can be conveniently used. 3. you can also split the post table
In Discuz! In x, you can easily use multiple databases and configure different database connections separately. The following two benefits are provided in the estimation.
1. if the load is sufficient, some tables can be distributed across multiple database servers. This reduces the load.
2. data in other databases can be conveniently used.
3. you can also split the posts into different database servers and split the posts into other databases.
Add the ing between the data table and the server in the/config/config_global.php file, and configure the corresponding database server. Add the following code
// 2 indicates the database connection parameters subsequently configured
$ _ Config ['DB'] ['map'] = array ('Table name' => '2 ');
// Here 2 corresponds to the ing configuration
$ _ Config ['DB'] ['2'] ['dbhost'] = 'localhost ';
$ _ Config ['DB'] ['2'] ['dbuser'] = 'root ';
$ _ Config ['DB'] ['2'] ['dbpw '] = '';
$ _ Config ['DB'] ['2'] ['dbcharset'] = 'gbk ';
$ _ Config ['DB'] ['2'] ['pconnect '] = '0 ';
$ _ Config ['DB'] ['2'] ['dbname'] = 'database name ';
// This parameter is useless. you can use it based on my subsequent modifications.
$ _ Config ['DB'] ['2'] ['tablepre'] = 'cdb _';
It is very convenient to use in the program. Directly use DB static objects
Print_r (DB: fetch_first ("SELECT * FROM". DB: table ('Table name'). "limit 1 "));
You must use the DB: table method to convert database connections.
Some table queries cannot be used.
The table prefix of the external database must be the same as the current table prefix. For example, pre _ table name
When the debug parameter is enabled, the system prompts that the table does not exist. Therefore, disable DEBUG.
Some additional modifications
If you want to use a non-Discuz table of another database, you can modify the table_name function of class_core so that you do not need to limit the prefix of the pre _ table. You can also use the database prefix in the configuration.
Function table_name ($ tablename ){
If (! Empty ($ this-> map )&&! Empty ($ this-> map [$ tablename]) {
$ Id = $ this-> map [$ tablename];
If (! $ This-> link [$ id]) {
$ This-> connect ($ id );
}
$ This-> curlink = $ this-> link [$ id];
// Added this sentence
Return $ this-> config [$ id] ['tablepre']. $ tablename;
} Else {
$ This-> curlink = $ this-> link [1];
}
Return $ this-> tablepre. $ tablename;
}