php链接mysql数据库数据添加和查询

$hostname="123456";

$username="123456";

$password="123456";

$database="123456";

$dbdriver="mysql";

//链接数据库

$conn = mysql_connect($hostname,$username,$password);

if(!$conn)

{

die("数据库链接失败:".mysql_error());

}

mysql_select_db("phzl",$conn);

print "数据库链接成功!!!

";

//查询数据库中的数据

$result = mysql_query("select * from student");

while($row = mysql_fetch_array($result))

{

print $row['firstname']." ".$row['lastname'];

print "

";

}

print "====================================";

print "

";

print "下面为条件查询。。。。。。";

print "

";

$res= mysql_query("select * from student where firstname='wang'");

while($row = mysql_fetch_array($res))

{

print $row['firstname']." ".$row['lastname'];

print "

";

}

/*

//数据库中插入数据

$sql =mysql_query("insert into student(id,FirstName,LastName)VALUE ('3','peter','pt')");

$sqll =mysql_query("insert into student(id,FirstName,LastName)VALUE ('4','Lili','Li')");

mysql_close();

*/

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20181107A15YB600?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。

扫码关注云+社区

领取腾讯云代金券