First open Zend to create a project and import our ThinkPHP.
Enter http://1270.0.1/text01 in the browser address bar and run the ThinkPHP project, you can see Think’s smiling face.
Related recommendations: "ThinkPHP Tutorial"
Create a database Create a user table for the database connection of our entire project , test whether the database is connected.
Open the project refresh and view the generated directory structure. Application->Common->Conf is the public configuration file directory of the project. You can see that there is a config under Conf. .php file, "Public Configuration File Directory" can be seen that this directory is a common directory for the front and backend. If the front and backend use a database to directly configure a database connection in the public directory, it can be used by both the front and backend. It can be used under config.php Write all public configuration files.
ThinkPHP has a built-in abstract database access layer that encapsulates different database operations. We only need to use the public Db class to operate without having to write different databases for different databases. The code and underlying implementation, the Db class will automatically call the corresponding database driver to process. Current databases include Mysql, SqlServer, PgSQL, Sqlite, Oracle, Ibase, Mongo, and support for PDO.
We have taken the mysql database as an example:
1 2 3 4 5 6 7 8 9 |
|
The database has been successfully connected. Try to see if you can access the database correctly. Open the project Home->Controller ->IndexController.class.php
1 2 3 4 5 |
|
Enter http://1270.0.1/text01 in the browser address bar and run the ThinkPHP project to see if the data is printed out. The test is successful. .
The above is the detailed content of How to connect thinkphp to the database. For more information, please follow other related articles on the PHP Chinese website!