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 method for discuz multi-database calling on the internet. today, I'm not sure this is the most suitable for disucz.
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. There is no method for calling discuz multi-database on the internet. today, I am not sure that this is the most suitable method for calling the multi-instance database code of disucz.
Successful case based on discuz 2.5
Modify conf/config_global.php
123456789 |
// Add database configuration information $ _ 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 _'; |
Modify source/class/class_core.php
12 |
// Add classDB_BIextendsdiscuz_database in the bottom row {} |
Copy soucrce/class/db_driver_mysql.php
Db_driver_mysql_bi.php
Modifying db_driver_mysql_bi.php
123456 |
// Modify the class name classdb_driver_mysql_bi.php // modify the serial number for reading the configuration file $ this-> tablepre = $ config ['2'] ['tablepre']; // Set the identifier of connect to functionconnect ($ serverid = 2 ){ |
Reference a new database code operation instance
1234567 |
$ 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 ); |