PHP查询mysql 并输出

PHP查询mysql 并输出 


慕田峪4524236
浏览 2405回答 2
2回答

拉风的咖菲猫

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

精慕HU

$sql=mysql_query("select name from use where id=123");$row=mysql_fetch_array($sql);echo $row["name"];这样就行
打开App,查看更多内容
随时随地看视频慕课网APP