<?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);
}
}