Premise:
(1) Create a new controller file named connect.php under the App\index\controller file
(2) Create a database named User_curd, which has a user table with the following table:
Connect to a database with global configuration ( recommended )
1. Open the global configuration file: think\config\databases.php
2, enter in the connect.php:
Enter the URL: localhost/tp5 the installation directory/think/public/index.php/index/connect/connect, the result is:
Connecting databases with dynamic configuration
1, open the global configuration, the relevant information to comment out
2. Enter in connect.php
3. Results:
Using DSN configuration to connect to a database
1, open the global configuration, the relevant information to comment out
2, enter in the connect.php:
Results:
Above
END
TP5.1: Connection Database (global configuration, dynamic configuration, DSN configuration)