Home>Article>Backend Development> How to add, delete, modify and check mysql in php
When PHP is connecting to the database in the following code, it uses the four major functions of mysql operations: add, delete, modify, and check. The source code is as follows:
Connect to the database
Add
$sql="insert into student(sname,sage) values('wx','18')"; $rs=mysql_query($sql,$conn); if($rs){ echo 'insert data success'."
"; }else{ echo 'insert data failed'."
"; }Delete
$sql="delete from student where sname='li'"; $rs=mysql_query($sql,$conn); if($rs){ echo 'del data success'."
"; }else { echo 'del data failed'."
"; }Modify
$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'."
"; }Query
$sql="select * from student"; $rs=mysql_query($sql,$conn); var_dump($rs); while($row=mysql_fetch_object($rs)){ print_r($row); echo ' '; echo $row->sname ."
">; } ?>The above is the detailed content of How to add, delete, modify and check mysql in php. For more information, please follow other related articles on the PHP Chinese website!