!DOCTYPE htmlhtml head titlemysql test/title /head body ?php $server_ip = '127.0.0.1'; $server_usename = "root"; $server_password = "123"; $conn = mysql_connect($server_ip,$server_usename,$server_password) or die("conn error:".mysql_error()
<!DOCTYPE html> <html> <head> <title>mysql test</title> </head> <body> <?php $server_ip = '127.0.0.1'; $server_usename = "root"; $server_password = "123"; $conn = mysql_connect($server_ip,$server_usename,$server_password) or die("conn error:".mysql_error()); mysql_select_db("dinning") or die("mysql select db error".mysql_error()); $result = mysql_query("select * from user"); $row_num = mysql_num_rows($result); while($field = mysql_fetch_field($result) ) { foreach ($field as $key => $value) { if($key == "name") { echo "$key => $value<br/>"; } } } echo "<br/>"."begin"."<br/>"; while($row = mysql_fetch_assoc($result)) { foreach ($row as $key => $value) { echo "$key => $value"; } mysql_free_result($result); echo "<br/>"; } echo "end"."<br/>"; mysql_close($conn); ?> </body> </html>