php 连接数据库并显示所要的数据

作者:袖梨 2022-06-24
 代码如下 复制代码

$Host="localhost";

  $MySQL_UserName="root";

  $MySQL_UserPass="password";

  $MySQL_Database="db";

  $Query="SELECT * FROM domain";

  if (!mysql_connect ($Host, $MySQL_UserName, $MySQL_UserPass)){

  print "Cannot connect to MySQL: ".mysql_error();

  exit;

  }

  if (!mysql_select_db ($MySQL_Database)){

  print "Cannot select db
";

  exit;

  }

  if (!$Result_ID=mysql_query ($Query)){

  print "Query Error: ".mysql_error();

  exit;

  }

  while ($Result=mysql_fetch_row($Result_ID)){

  print "------------------
";

  print "$Result[0]
";

  print "$Result[1]
";

  print "$Result[2]
";

  print "$Result[3]
";

  print "-------------------
";

  }?>

相关文章

精彩推荐