拉风的咖菲猫
PHP查询MySQL并输出使用的是SELECT 语句。语法:1SELECT column_name(s) FROM table_nameSELECT 语句用于从数据库中选取数据。示例:选取存储在 "Persons" 表中的所有数据(* 字符选取表中所有数据)12345678910111213141516171819<?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } mysql_close($con);?>在 HTML 表格中显示结果12345678910111213141516171819202122232425262728<?php$con = mysql_connect("localhost","peter","abc123");if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; }echo "</table>"; mysql_close($con);?>以上代码的输出: