Configure the connected database in thinkphp

Source: Internet
Author: User
1. add the database configuration information to config. inc. php in the same directory as the thinkphp entry File & lt ;? Phpreturnarray (& amp; #39; DB_TYPE & amp; #39; & gt; & amp; #39; mysqli & amp; #39;, & amp; #39; DB_HOST & amp ;...

1. add the database configuration information to config. inc. php in the same directory as the thinkphp entry file.

  1. Return array (
  2. 'Db _ type' => 'mysqli ',
  3. 'Db _ host' => 'localhost ',
  4. 'Db _ name' => 'demo ',
  5. 'Db _ user' => 'root ',
  6. 'Db _ pwd' => 'root ',
  7. 'Db _ prefix' => 'think _',
  8. );
  9. ?>

Add the following code to the config. php file of the project directory:

  1. $ Arr1 = array (
  2. // 'Config maps '=> 'configuration value'
  3. 'URL _ model' => 2,
  4. 'App _ debug' => true,
  5. 'Log _ RECORD '=> true,
  6. ......
  7. );
  8. $ Arr2 = include 'config. inc. php ';
  9. Return array_merge ($ arr1, $ arr2 );
  10. ?>

You can also add the above code in the background file. after the connection information of the database configuration is changed, you only need to modify config. inc. the information in the PHP file allows you to modify the database connection configuration of the front-end and back-end at the same time.

2. if you want to connect to another database in the controller, add the following code:

  1. $ Arrr = array (
  2. 'Dbms '=> 'mysqli', // note that the key name in the group in this book cannot be changed.
  3. 'Username' => 'Google ',
  4. 'Password' => 'hello ',
  5. 'Hostname' => '2017. 0.0.1 ',
  6. 'Database' => 'mydbname ',
  7. );
  8. $ Db = new Db ($ arrr );

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.