PHP基础连接数据库并查询数据

<?php


header("Content-Type: text/html; charset=utf-8");
$con = mysql_connect("localhost","root","admin");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("yuwq", $con);


$result = mysql_query("SELECT * FROM user");


while($row = mysql_fetch_array($result))
  {
  echo $row['Id'] . " " . $row['name'];
  echo "<br />";
  }


mysql_close($con);
?>

你可能感兴趣的:(PHP学习)