The following article describes how to use php to query MySQL Data. This document describes how to use php to query MySQL Data, the following is a detailed description of the article. I hope you will have a better understanding of it.
- <?php
- $link = mysql_connect('localhost', 'root', '123456')
- or die('Could not connect: ' . mysql_error());
- mysql_select_db('ruida') or die('Could not select database');
Execute SQL query
- $query = 'SELECT * FROM product';
- $result = mysql_query($query) or die('Query failed: ' . mysql_error());
Display Results in HTML
- echo "<table>\n";
- while ($line = mysql_fetch_assoc($result)) {
- echo "\t<tr>\n";
- foreach ($line as $col_value) {
- echo "\t\t<td>$col_value</td>\n";
- }
- echo "\t</tr>\n";
- }
- echo "</table>\n";
Release result set
- mysql_free_result($result);
Close connection
- mysql_close($link);
- ?>
The above content is an introduction to querying MySQL Data in php. I hope you will find some gains.