How to configure multiple databases in Discuzx2.5x3.0

Source: Internet
Author: User
What should I do? This is... Embarrassed .... Some of the user's data is sourced from another instance in the same database and needs to be changed to a cross-database instance. In fact, it is easy for me to create an api or call a database directly. The api can also be used as a cache. Unfortunately, I know little about another project. There is no calling method for discuz multi-database on the Internet today

What should I do? This is... Embarrassed ....

Some user data information is sourced from another instance in the same database and needs to be changed to cross-database.

In fact, it is easy for me to create an api or call a database directly. The api can also be used as a cache. Unfortunately, I know little about another project. No information aboutDiscuzThe multi-database call method today brings you a multi-instance database code call that I'm not sure is the most suitable for disucz, but must be useful.

Successful case based on discuz 2.5
Modify conf/config_global.php

1

2

3

4

5

6

7

8

9

 

$ _ Config ['DB'] ['2'] ['dbhost'] = '2017. 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 _';

 

// Read those tables from another database

$ _ Config ['DB'] ['map'] ['Nav'] = 2;

Modify source/class/db/db_driver _MysqlAdd a field to the table_name function in. php.

 

 

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];
// Add this sentence from the database
Return $ this-> config [$ id] ['tablepre']. $ tablename;
} Else {
$ This-> curlink = $ this-> link [1];
}
Return $ this-> tablepre. $ tablename;
}

 

 

 

Run successfully

Print_r (DB: fetch_first ("SELECT * FROM". DB: table ('Nav'). "limit 1 "));

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.