php连接mysql,并实现增删改查

    xiaoxiao2022-07-03  150

    <?php header("Content-type:text/html;charset=utf-8"); $conn=mysql_connect("localhost","root","root"); if($conn){ echo "链接成功"; mysql_select_db("zhangsan"); } else{ echo "连接失败"; } //增 // mysql_query("insert into student values(1,'张三','女',22)",$conn); // mysql_query("insert into student values(2,'李四','男',25)",$conn); // mysql_query("insert into student values(3,'老王','M',6)",$conn); //删 //mysql_query("delete from student where stuid=1",$conn); //改 //mysql_query("update student set stuName='小王' where stuName='老王'",$conn); //查 //$result = mysql_query("select * from student",$conn); $result=mysql_query("select * from student",$conn); //返回当表格的行数 if(mysql_num_rows($result)>0){ //mysql_fetch_assoc将每一行的数据以集合(josn对象)的方式返回 while($row=mysql_fetch_assoc($result)){ echo $row["stuId"]." ".$row["stuName"]; } } ?>
    最新回复(0)