Home > Article > Backend Development > How to output sql query results in php
Method: 1. Use the "mysql_connect()" and "mysql_select_db()" functions to establish a connection with the database; 2. Use the "mysql_query()" function to execute the query statement "select * from table name"; 3. Use the echo statement to output the query results.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Use navicat to create a new database database1, and create a new database database1 in database1 Create a new table table2 in the database, add new data in table2, and create a new php file named mysql_query
php outputs sql query results
1. Use the mysql_connect function to establish a connection with the database on the page, and use the mysql_select_db function to select the database to be queried. .
2. Add a query statement "$sql=select * from table2" to query the table2 table.
#3. Add the query statement $sql to the query database function mysql_query, and assign the return value to the variable query. Finally, open the mysql_query.php file in the browser to view the results of querying the content in the database.
Recommended: "2021 PHP interview questions summary (collection) " "php video tutorial》
The above is the detailed content of How to output sql query results in php. For more information, please follow other related articles on the PHP Chinese website!