ThinkPhp学习07
简单CRUD操作
1 public function show() { 2 $m=M('User'); 3 4 // $arr=$m->find(2); //查找id=2的数据,find只能返回一条数据 5 //2.SELECT * FROM `tp_user` WHERE ( sex=1 ) 6 // $arr=$m->where('sex=1')->select(); 7 8 //3.INSERT INTO `tp_user` (`username`,`sex`) VALUES ('王五',1) 9 // $m->username22="王四"; 10 // $m->seeee=1; //如果对应的字段名不正确则不加入,所以要设置好是否为空,或者默认值 11 // $arr=$m->add(); //返回添加成功对应的id 12 13 14 //4.DELETE FROM `tp_user` WHERE ( `id` = 2 ) 15 //$arr=$m->delete(2); //返回删除成功条数 16 17 //3.DELETE FROM `tp_user` WHERE ( sex=0 ) 18 //$arr=$m->where('sex=0')->delete(); 19 20 // 2.UPDATE `tp_user` SET `username`='李明',`sex`=0 WHERE ( `id` = 1 ) 21 $data['id']=4; 22 $data['username']='李明2'; 23 $data['sex']=0; 24 $arr=$m->save($data); //返回成功执行数 25 echo $arr; 26 27 $this->display(); 28 }