Home > Article > Backend Development > How to use database in php
First we need to create a database in the MYSQL database, as shown in the figure below:
Then use EditPlus to create a php file , write the following connection statement, mainly using the mysql_connect method.
Related recommendations: "php environment construction"
Then you need to add header encoding information on top of the connection statement, as shown in the figure below Display, telling the browser to use utf-8 for encoding.
#After running the program, you will see the prompt as shown below on the browser interface, which means the database connection is successful.
If we change the password for the database connection, as shown in the figure below, let’s test whether it is successful.
At this time, you will see the content as shown below on the page. The connection has reported an error and prompts that the connection failed.
To sum up, using PHP to connect to the MYSQL database is mainly done through the mysql_connect method. Please note that the username and password must be written correctly.
The above is the detailed content of How to use database in php. For more information, please follow other related articles on the PHP Chinese website!