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.
-
- Return array (
- 'Db _ type' => 'mysqli ',
- 'Db _ host' => 'localhost ',
- 'Db _ name' => 'demo ',
- 'Db _ user' => 'root ',
- 'Db _ pwd' => 'root ',
- 'Db _ prefix' => 'think _',
- );
- ?>
Add the following code to the config. php file of the project directory:
-
- $ Arr1 = array (
- // 'Config maps '=> 'configuration value'
- 'URL _ model' => 2,
- 'App _ debug' => true,
- 'Log _ RECORD '=> true,
- ......
- );
- $ Arr2 = include 'config. inc. php ';
- Return array_merge ($ arr1, $ arr2 );
- ?>
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:
- $ Arrr = array (
- 'Dbms '=> 'mysqli', // note that the key name in the group in this book cannot be changed.
- 'Username' => 'Google ',
- 'Password' => 'hello ',
- 'Hostname' => '2017. 0.0.1 ',
- 'Database' => 'mydbname ',
- );
- $ Db = new Db ($ arrr );