<?php $conn=mysql_connect('localhost','root',''); if(!$conn){ echo "connect failed"; exit; } $sql='use student'; mysql_query($sql,$conn); //增加 $sql="insert into student(sname,sage) values('pu','20')"; $rs=mysql_query($sql,$conn); if($rs){ echo 'insert data success'."
"; }else{ echo 'insert data failed'."
"; } //修改 $sql="update student set sname='fu' where sname='pu'"; $rs=mysql_query($sql,$conn); if($rs){ echo 'update data success'."
"; }else{ echo 'update data failed'."
"; } //删除 $sql="delete from student where sname='li'"; $rs=mysql_query($sql,$conn); if($rs){ echo 'del data success'."
"; }else { echo 'del data failed'."
"; } //查询 $sql="select * from student"; $rs=mysql_query($sql,$conn); //打印变量的相关信息 var_dump($rs); //遍历从结果集中取行 mysql_fetch_array/assoc/row/object while($row=mysql_fetch_object($rs)){ print_r($row); echo ' '; echo $row->sname; echo "
"; } ?>
php操纵mysql的增删改_php连接Mysql的增删改查操作
最新推荐文章于 2024-03-29 22:17:22 发布