增加数据
"p005","Name"=>"妈拉巴子" ,"Sex"=>1,"Nation"=>"n003","Birthday"=>"1999-02-03"); $db->add($arr); //2.使用映射的方式 $db->Code = "P006"; $db->Name = "你妹"; $db->Sex = 1; $db->Nation = "C004"; $db->Birthday = "1996-03-04"; $db->add(); }}
自动收集表单的方法
首先在index文件夹中新建一个add文件
assign("d","134212534");; } public function add(){ $db = D("Info"); //3.自动收集表单 if(empty($_POST)){ $arr = $db ->table("Nation") ->select(); $this->assign("arr",$arr); $this->show(); }else{ $db->create();//收集表单 $db->add(); } }}
========
修改数据
assign("d","134212534");; } public function add(){ $db = D("Info"); //3.自动收集表单 if(empty($_POST)){ $arr = $db ->table("Nation") ->select(); $this->assign("arr",$arr); $this->show(); }else{ $db->create();//收集表单 $db->add(); } } public function update(){ $db = D("Info"); $code = "p002"; if(empty($_POST)){ $nation = $db ->table("Nation") ->select(); $info = $db ->find($code); $this->assign("info",$info); $this->assign("nation",$nation); $this->show(); }else{ $db->create(); $db->save(); } }}
========
删除数据
assign("d","134212534");; } public function add(){ $db = D("Info"); //3.自动收集表单 if(empty($_POST)){ $arr = $db ->table("Nation") ->select(); $this->assign("arr",$arr); $this->show(); }else{ $db->create();//收集表单 $db->add(); } } public function update(){ $db = D("Info"); $code = "p002"; if(empty($_POST)){ $nation = $db ->table("Nation") ->select(); $info = $db ->find($code); $this->assign("info",$info); $this->assign("nation",$nation); $this->show(); }else{ $db->create(); $db->save(); } } public function del(){ //$code = "p006"; $db = D("Info"); //$db->delete($code); $sql = "delete from info where code = 'p004'"; $db->execute($sql); //这里也适用于sql原生语句,增删改用execute 查用query }}