欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP增删改查的容易实现

程序员文章站 2022-04-11 14:13:08
...
PHP增删改查的简单实现

come from http://hi.baidu.com/javashmily/item/69d117fc3ebbdd723d198b9e

//获得连接
$db = mysql_connect("localhost", "root", "root") or die(mysql_error());
echo "Connected to MySQL
";
//连接数据库
mysql_select_db("php") or die(mysql_error());
echo "Connected to Database";
//增加操作
if ($submit){????????????????????????????????????????????????????????????????
??? $sql = "INSERT INTO student (id,name) VALUES ('$id','$name')";??????????????????
??? $result = MySQL_query($sql);????????????????????????????????????
??? echo "记录添加成功!

";?????????????????????????????????
??? }
??? //删除操作
??? if($delete){
??? $sql ="delete from student where id = $id";
??? $result = mysql_query($sql);
??? echo "删除了id为 $id 的记录 ";
??? }
??? //修改操作
??? if($update){
??? $sql = "update student set name='$name' where id = $id";
??? $result = mysql_query($sql);
??? echo "修改成功!!";
??? }
??? //查询数据,并用表格显示出来
??? $result = mysql_query("select * from student",$db);

echo "

\n";??????????????????????????????????????
??? echo "";?????????????????????????????????????????????????????
??? echo "\n";?????????????????????????????????????????????????
??? //循环遍历??????????????????????????????????????????????????????????
while ($myrow = mysql_fetch_row($result)){???????????????????????????????????????????????????????????????
??? printf("", $myrow[0], $myrow[1]);
??? }???????????????????????????????????????????????????????????????
echo "
id 姓名
%s %s
\n";
?>


??

??

??
??
??

PHP增删改查的容易实现

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • PHP增删改查的容易实现
  • 专题推荐