返回 查询构造器中的...... 登陆

查询构造器中的增删改查

Free flight 2019-07-05 11:29:18 194

<?php

namespace app\index\controller;

use think\Db;

use think\Controller;

use app\index\model\Goods;



Class Mydbtest extends Controller

{

public function query()

{

//查询一条数据

//$res = DB::table('goods')->where('id',2)->select();


//多条件查询

//$res = DB::table('goods')->where(['name'=>'光纤熔接机','price'=>'20000'])->select();

//$res = DB::table('goods')->where('id=:id')->bind(['id'=>[2,\PDO::PARAM_INT]])->fetchsql()->find();


/*$res = DB::table('goods')->where('name=:name')->bind(['name'=>'光纤熔接机'])->count();*/

//$res = DB::table('goods')->where('name=:name')->bind(['name'=>'光纤熔接机'])->max('price');

$res = DB::table('goods')->where('name=:name')->bind(['name'=>'光纤熔接机'])->avg('price');

dump($res);

}

public function add(){

//$data = array('name'=>'光纤熔接机','brand'=>'住友1','price'=>'19500');

// Db::table('goods')->insert($data);

$data = 

array('name'=>'熔接机1','brand'=>'住友2','price'=>'19501')


;

$res = Db::table('goods')->insertGetid($data);

//echo('好的');

var_dump($res);

public function updatas(){

$data = array('name'=>'切割刀');

$res = Db::name('goods')->where('id',11)->update($data);

var_dump($res);

}

public function inc(){

$id = $this->request->param('id');

$res = Db::name('goods')->where('id',$id)->setInc('number');

var_dump($res);

}

public function dec(){

$id = $this->request->param('id');

$res = Db::name('goods')->where('id',$id)->setDec('number',rand(10,20));

var_dump($res);

}

public function delete(){

$id = $this->request->param('id');

$res = Db::name('goods')->where('id',$id)->delete();

var_dump($res);

}

public function models(){

//$res=Goods::where('id','>',3)->select();

//$data = array('name'=>'切割刀2','price'=>1300);

// //$res=Goods::insert($data);

// $Goods = new Goods;

// $Goods->save($data);

// $res = $Goods->id;


Goods::where('id',14)->delete();

//var_dump($res);

}

}


最新手记推荐

• 用composer安装thinkphp框架的步骤 • 省市区接口说明 • 用thinkphp,后台新增栏目 • 管理员添加编辑删除 • 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消 回复 发送
  • PHP中文网