: This article mainly introduces how PHP configures the database information of a model separately. if you are interested in the PHP Tutorial, refer to it. 131 how does thinkphp link a model in the project to another database?
Requirement: a sub-project needs to call the public header (model) of another project. the header is different from the storage database of the sub-project. If this parameter is not set, the table corresponding to the header will be searched in the database configured for the sub-project, which obviously does not exist. Solution
- Write db information to the model class constructor in the header
Function_initialize () {// Set the database link $ this-> connection = C ("SYS_CONFIG"); // Set the prefix $ this-> setProperty ("tablePrefix", SYS_DB_PREFIX ); // execute the parent class constructor parent: _ initialize ();}
- Write specific configuration in the configuration file
'SYS_CONFIG' => array( 'db_type' => SYS_DB_TYPE, 'db_host' => SYS_DB_HOST, 'db_name' => SYS_DB_NAME, 'db_user' => SYS_DB_USER, 'db_pwd' => SYS_DB_PWD, 'db_prefix' => SYS_DB_PREFIX, 'db_port' => SYS_DB_PORT, 'wkhtmltopdf_path' => SYS_WKHTMLTOPDF_PATH,),
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces how to configure the database information of a model separately in php 131, including some content, and hope to help those who are interested in the PHP Tutorial.