First, find the config in the Conf sub-directory under the Common directory in the project file directory. add the following code to the PHP file: DB_TYPE & amp; gt; pdo, DB_USER & amp; gt; root, DB_PWD & amp; gt; database password, DB_PREFIX & amp; gt; think _, table prefix DB_DSN & amp; gt; mysql :... first, find the config in the Conf sub-directory under the Common directory in the project file directory. php file
Add the following code:
'Db _ type' => 'pdo ',
'Db _ user' => 'root ',
'Db _ pwd' => 'Database password ',
'Db _ prefix' => 'think _ ', table PREFIX
'Db _ DSN '=> 'MySQL: host = localhost; dbname = name of the connected database; charset = utf8'
Note: charset = UTF8 instead of the UTF-8, an error will be reported when writing the UTF-8 page.
Another method is as follows:
Model (['model name'], ['data table prefix'], ['database connection information']); the database is defined in the connection information of the third parameter database.
For example, $ user = new Model ('user', 'think _ ', 'MySQL: // root: 123456 @ localhost/thinkphp ');
Database Connection information format: Database type: // user name: password @ database address: database port/database name # Character set
This example is modified based on actual conditions.