第三课 skymvc模型的使用

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";
	}
}

?>

 

转载于:https://my.oschina.net/lrjxgl2/blog/680105

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值