Discuzx2.5 multi-database instance call method

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

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.