thinkphp configuration database connection common file and project personalization configuration Merge

Source: Internet
Author: User

Because all applications (projects) of the entire site need to be connected to the database, they should be set up separately in each project's configuration file. In the future if the database connection information has been modified, you have to modify the configuration file one, so it is not suitable for lazy people. Because the near-ink note that thinkphp's project configuration file is in array form, we can solve this problem by merging arrays. First, create a new config.inc.php file at the root of the Web site and write the database configuration parameters to the array

<?phpreturn Array (' db_type ' = ' mysql ', ' db_host ' = ' localhost ', ' db_name ' = ' oa ', ' db_user ' = ' root ', ' Db_pwd ' = = ', ' db_port ' = ' 3306 ', ' db_prefix ' = ' think_ ', ' show_page_trace ' = true,];? >

Then to the Project Profile conf/config.php, merge the personalization configuration with the public configuration parameters and return the array

$config _arr1 = include ('./config.inc.php '); $config _arr2 = Array (' site_name ' = ' site name ', ' site_title ' = ' website title ', ' Site_url ' + ' website link ', '); return Array_merge ($config _arr1, $config _arr2);

Then use C (' own defined name ') in the project to invoke the information of the merged configuration file

thinkphp configuration database connection common file and project personalization configuration Merge

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.