First find the config.php file in the Conf subdirectory of the Common directory in the project file directory
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=Connected database name;charset=UTF8'
Note: charset=UTF8 instead of UTF-8. Writing UTF-8 web pages will result in an error.
There is another method: for model instantiation using Model(), you can do it in:
Model(['Model name'], ['Data table prefix'], ['Database connection information']); Define the database in the three parameters database connection information
For example: $user = new Model('User','think_','mysql://root:123456@localhost/thinkphp');
The format of the database connection information is: Database type://username:password@database address:database port/database name#character set
This example should be modified according to the actual situation
The above introduces how to connect to the mysql database through the pdo method in thinkPHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.