新增方法
$affected = Db::table('destoon_ad')
->insert([
'pid'=>'2018',
'url'=>'www.baidu.com'
]);
return $affected ? '成功添加'.$affected.'条数据' : '添加失败';
批量新增
$affected = Db::table('destoon_ad')
->insertAll([
['pid'=>55,'url'=>'www.sohu.com'],
['pid'=>66,'url'=>'www.360.com'],
['pid'=>77,'url'=>'www.163.com'],
]);
return $affected ? '成功添加'.$affected.'条数据' : '添加失败';
------------------------------------------------------------------------------------
更新操作
$affected = Db::table('destoon_ad')
->where('pid',77)
->update([
'url'=>'www.hao123.com'
]);
return $affected ? '成功更新'.$affected.'条数据' : '更新失败';
自增/自减操作
$affected = Db::table('destoon_ad')
->where('pid',14)
->setInc('hits',10); //setDec('hits',10); 延时更新加第三个参数,单位为秒 setInc('hits',10,3);
return $affected ? '成功更新'.$affected.'条数据' : '更新失败';
------------------------------------------------------------------------------------
查询操作
$result = Db::table('destoon_ad')->where('aid',1)->value('url');
dump($result);
例查询
$result = Db::table('destoon_ad')->where('aid','>',1)->column('url');
dump($result);
------------------------------------------------------------------------------------
删除操作
$affected = Db::table('destoon_ad')->where('pid',77)->delete();
dump($affected);