//查询主键为2的记录 //$list = M('goods')->select(2); //批量查询这些主键 //$list = M('goods')->select("1,2,3,4,5,6,9"); //where条件查询 //$list = M('goods')->where("goods_price > 2000 and goods_name like '%诺基亚%'")->select(); //limit //$list = M('goods')->limit(5)->select();//相当于limit(0,5) 第一个参数是从 哪里开始第二个参数是获取多少条 //where 和 limit // $list = M('goods')->where('goods_price > 2000')->limit(3)->select(); //排序 // $list = M('goods')->order('goods_price desc')->select(); //默认是升序 desc是降序 //查询指定字段 // $list = M('goods')->field('goods_name,goods_price')->select(); //having // $list = M('goods')->having('goods_price>4000')->select(); $list = D('goods')->group('goods_brand_id')->field('goods_brand_id,max(goods_price) as m') ->limit(3)->having('m>2000')->select(); $this->assign("list",$list);
select * from 表 where 条件 group by 分组 having 条件
public function test2(){ $data = array( 'goods_name'=>'dashouji', 'goods_price'=>'343' ); echo M('goods')->add($data); }
ublic function test3(){ $data=M('goods'); $data->goods_name = 'shoujishi'; $data->goods_price = 090; $data->add(); }
public function test4(){ $data = array( 'goods_price'=>121, 'goods_name'=>'shouji233', 'goods_id' => 141 ); echo M('goods')->save($data); //返回受影响的记录条数 }
public function test5(){ $data = M('goods'); $data->goods_name = "sds"; $data->goods_id=150; echo $data->save(); }
public function test6(){ // echo M('goods')->delete(141); //echo M('goods')->delete("150,151"); // echo M('goods')->where("goods_name = 'apple'")->delete(); $model = M('goods'); $model->goods_id = 138; echo $model->delete(); } }
public function test7(){ //查询的时候使用 query // $list = M()->query('SELECT * FROM SW_GOODS'); //增删改用execute方法 $list = M()->execute('DELETE FROM SW_GOODS WHERE GOODS_ID = 133'); var_dump($list); }