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 "));