Discuz! X forum configuration uses multiple databases

Source: Internet
Author: User
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;



}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.