How to query mysql database data in php: First use navicat to create a new database and create a table; then add data and connect to the database; then use the [mysql_select_db] function to select the database to be queried; finally, put the file in the browser Just open it in .
![How to query mysql database data in php?](https://img.php.cn/upload/article/202007/18/2020071813502067228.jpg)
How to query mysql database data in php:
1. Use navicat to create a new database database1
![1595051337515007.png How to query mysql database data in php?](https://img.php.cn/upload/image/283/281/791/1595051337515007.png)
2. Create a new table table2 in the database1 database
![1595051342972743.png How to query mysql database data in php?](https://img.php.cn/upload/image/383/513/667/1595051342972743.png)
##3. Add new data in table2
![1595051348970714.png How to query mysql database data in php?](https://img.php.cn/upload/image/201/173/102/1595051348970714.png)
4. Create a new database named mysql_query
![1595051354529281.png How to query mysql database data in php?](https://img.php.cn/upload/image/704/820/472/1595051354529281.png)
5. Use the mysql_connect function to establish a connection with the database on the page
![1595051361541951.png How to query mysql database data in php?](https://img.php.cn/upload/image/523/876/383/1595051361541951.png)
6. Use the mysql_select_db function to select the database to be queried
![1595051368398533.png How to query mysql database data in php?](https://img.php.cn/upload/image/133/656/786/1595051368398533.png)
7. Add a query statement for querying the table2 table "
$sql=select * from table2“
Copy after login
![1595051375519427.png How to query mysql database data in php?](https://img.php.cn/upload/image/657/894/950/1595051375519427.png)
8. Add the query statement $sql to the query database function mysql_query, and assign the return value to the variable query
![1595051383404782.png How to query mysql database data in php?](https://img.php.cn/upload/image/921/949/691/1595051383404782.png)
9. Define an array arr, use the mysql_fetch_assco function to obtain the query results, use while traversal to store the query results into the array arr
, and finally print arr.
![1595051388200684.png How to query mysql database data in php?](https://img.php.cn/upload/image/312/346/682/1595051388200684.png)
10. Open the mysql_query.php file in the browser and view the results of querying the content in the database
![1595051394190781.png How to query mysql database data in php?](https://img.php.cn/upload/image/228/928/405/1595051394190781.png)
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of How to query mysql database data in php?. For more information, please follow other related articles on the PHP Chinese website!