131 thinkphp How to link a model in a project to another database separately
Requirements: A subproject needs to invoke the public header (model) of other projects, and the head and sub-project storage database is different, if not set, will be in the sub-project configuration database to look for the head corresponding table, obviously does not exist.
Solution
- Writes the DB information to the constructor of the model class in the header
function_initialize() {//设置数据库链接$this->connection = C("SYS_CONFIG"); //设置前缀$this->setProperty("tablePrefix", SYS_DB_PREFIX); //执行父类构造函数parent::_initialize();}
- Write a 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); }); });
The above describes how 131 PHP will be a model of the database information is configured separately, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.