131 How PHP Configures database information for a model separately

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

  • 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.