PHP如何从MySQL数据库中选择数据

欢迎您,来自IP地址为:54.166.172.180的朋友

付款前,可以输入宝贝名称查一查有没有优惠券可以用哦!


步骤1:连接MySQL数据库

 <?php

$DatabaseServer = "localhost";
$DatabaseUsername = "root";
$DatabasePassword = "root";
$DatabaseName = "demo";

$Connection = mysqli_connect($DatabaseServer , $DatabaseUsername , $DatabasePassword , $DatabaseName);

if($Connection === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

?>

步骤2:从MySQL数据库中获取数据

 <?php

$SQL = "SELECT * FROM user";
$Result = mysqli_query($Connection, $SQL);
while($Row = mysqli_fetch_assoc($Result)
    {
   echo $FirstName = $Row['FirstName '];
   echo $Email = $Row['Email'];
    }

?>

MySQL数据库需要执行的语句

 CREATE TABLE 'use' (
  'UserID' int(12) NOT NULL,
  'FirstName' varchar(48) NOT NULL,
  'LastName' varchar(48) NOT NULL,
  'Email' varchar(128) NOT NULL,
  'City' varchar(48) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

  INSERT INTO 'user' ('UserID', 'FirstName', 'LastName', 'Email', 'City') VALUES
  (1, 'Ram', 'Sri', 'zzz@zzz.com', 'Delhi'),
  (2, 'Krishna', 'Vasudev', 'yyy@yyy.com', 'Delhi');

发表评论

电子邮件地址不会被公开。 必填项已用*标注