Blogger Information
Blog 4
fans 0
comment 0
visits 2355
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
5月23日作业
clin
Original
526 people have browsed it
实例
<?php
namespace app\index\controller;
use think\Db;
class Clin{

	// 数据查询
	public function findR(){
		$re = Db::table('user') -> find();
		dump($re);
	}

	public function selectR1(){
		$re = Db::table('user') -> select();
		dump($re);
	}

	public function selectR2(){
		$re = Db::table('user') -> select(6);
		dump($re);
	}

	public function selectR3(){
		$re = Db::table('user') 
			-> where('id = 6') 
			-> select();
		dump($re);
	}

	public function selectR4(){
		$re = Db::table('user') 
			-> field('id,username,create_time')
			-> select();
		dump($re);
	}

	public function selectR5(){
		$re = Db::table('user') 
			-> field('id, username as 用户名, create_time as 创建时间')
			-> select();
		dump($re);
	}

	public function selectR6(){
		$re = Db::table('user') 
			-> field(['id','username'=>'用户名','create_time'=>'创建时间'])
			-> select();
		dump($re);
	}

	public function selectR7(){
		$re = Db::table('user') 
			-> field('id,username,create_time')
			-> order('create_time desc')
			-> select();
		dump($re);
	}

	public function selectR8(){
		$re = Db::table('user') 
			-> field('id,username,create_time')
			-> order('create_time','asc')
			-> select();
		dump($re);
	}

	public function selectR9(){
		$re = Db::table('user')
			-> where('id','15')
			-> select();
		dump($re);
	}

	public function selectR10(){
		$re = Db::table('user')
			-> where('id','<','5')
			-> select();
		dump($re);
	}

	public function selectR11(){
		$re = Db::table('user')
			-> where('id','<','8')
			-> limit(3)
			-> select();
		dump($re);
	}

	public function in(){
		$data = [
				'name' => '李白',
				'sex' => 1,
				'age' => 19,
				'salary' => 6379
			];
		$re = Db::table('staff') -> data($data) -> insert();
		$id = Db::getLastInsID();
		return $re.' >> '.$id;
	}

	public function ing(){
		$data = [
				'name' => '李灵',
				'sex' => 1,
				'age' => 19,
				'salary' => 6379
			];
		$re = Db::table('staff') -> insertGetId($data);
		return $re;
	}

	public function ins(){
		$data = [
			['name'=>'杜甫','sex'=>1,'age'=>32,'salary'=>4920],
			['name'=>'诗人','sex'=>0,'age'=>5,'salary'=>53434],
		];
		$re = Db::table('staff') -> data($data) -> insertAll();
		return $re;
	}

	public function update(){
		$re = Db::table('staff')
			-> where('salary','>=',8500)
			-> data(['salary' => Db::raw('salary-1000')])
			-> update();
		return $re;
	}
	
	public function del(){
		$re = Db::name('staff') -> delete(12);
		return $re;
	}
	
	public function dels(){
		$re = Db::name('staff') -> delete([1,5,9]);
		return $re;
	}
}
运行实例 »
点击 "运行实例" 按钮查看在线实例

find.png

sel1.png

sel2.pngsel3.pngsel4.pngsel5.pngsel6.pngsel7.pngsel8.pngsel9.pngsel10.pngsel11.pngin.pnginget.pnginall.pngupdate.pngdel.pngdels.png

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post