skymvc官方教程:第3课 skymvc模型的使用
【视频】
/**********
*大家好,今天给大家讲讲skymvc的model。
*我们继续从hello world 开始。
*hello.model.php文件位于source/model目录下
*模型的命名$m.model.php 一个表对应一个model 当然model文件不是必须的 系统会自动处理
*文件整体结构可以看下
*/
所有方法: public function Model(){ /**** //select M("hello")->select() //selectRow M("hello")->selectRow(); //insert M("hello")->insert($data); //update M("hello")->update($data); //delete M("hello")->delete($data); */ $option=array( "where"=>" bstatus<11 ", "start"=>0, "limit"=>2, "fields"=>"*", "order"=>"id DESC" ); /* $rscount=true; //select $data=M("hello")->select($option,$rscount); echo "\r\n----select----\r\n"; print_r($data); echo "\r\n".$rscount; //复杂查询 echo "\r\n-------get------\r\n"; $data=M("hello")->getAll("select * from ".table('hello')." where bstatus<11 order by id desc limit 0,2 "); $rscount=M("hello")->getOne(" select count(1) from ".table('hello')." where bstatus<11 "); echo "\r\n----select----\r\n"; print_r($data); echo "\r\n".$rscount; //selectRow $option['limit']=1; $row=M("hello")->selectRow($option); print_r($row); //简单查询 M("hello")->selectRow("id=".$row['id']); M("hello")->getRow("select * from ".table('hello')." where bstatus<11 order by id desc limit 1"); //selectCols $option['fields']="id"; $cols=M("hello")->selectCols($option); M("hello")->getCols("select id from ".table('hello')." where bstatus<11 order by id desc limit 2"); print_r($cols); //selectOne $option['limit']=1; $one=M("hello")->selectOne($option); print_r($one); M("hello")->getOne("select id from ".table('hello')." where bstatus<11 order by id desc limit 2"); //changenum $option['limit']=1; $row=M("hello")->selectRow($option); print_r($row); M("hello")->changenum("bstatus",-1,"id=".$row['id']); $row=M("hello")->selectRow($option); print_r($row); */ $option=array( "where"=>" bstatus<11 ", "start"=>0, "limit"=>2, "fields"=>"*", "order"=>"id DESC" ); $idlist=M("hello")->idlist($option); print_r($idlist); } hello.model.php <?php /** *Author 雷日锦 362606856@qq.com *model 自动生成 */ class helloModel extends model{ public $base; public function __construct(&$base){ parent::__construct($base); $this->base=$base; $this->table="hello"; } } ?>