1、修改數據 update
update 方法返回影響數據的條數,沒修改任何數據返回 0
public function index(){
$data = ['price'=>'68'];
$update = Db::table('shop_goods')->where('id',8)->update($data);
print_r($update);
}
2、自增 inc
inc 方法自增一個字段的值
public function index(){
$inc = Db::table('shop_goods')->where('id',5)->inc('stock')->update();
print_r($inc);
# 字段的值增加5
$inc = Db::table('shop_goods')->where('id',6)->inc('stock',5)->update();
print_r($inc);
}
3、自減 dec
dec 方法自減一個字段的值
public function index(){
# 字段的值減去1
$dec = Db::table('shop_goods')->where('id',7)->dec('stock')->update();
print_r($dec);
# 字段的值減去5
$dec = Db::table('shop_goods')->where('id',8)->dec('stock',5)->update();
print_r($dec);
}
文章來自 www.eaful.cn