--------------------------------------------------------------------------------
$idArr = array('1','2','3','4')
$update = Db::name('task666')->where('id', 'in', $idArr)->update(['mark' => 1]);
//$update = 4(更新的条数)
$del = Db::name('task666')->where('id', 'in', $idArr)->delete();
//$del = 4(删除的条数)
--------------------------------------------------------------------------------
$trunkArr = Db::name('trunk t')
->field('t.key,t.ip')
->join('package p', 'p.trunk_number=t.number', 'inner')
->where('p.number', 'in', $packageArr)
->group($filter)->select();
--------------------------------------------------------------------------------
$originData = Db::query("select surplus from package where id in ($pcgStr) for update");
--------------------------------------------------------------------------------
$tempPcgArr 为一位索引数组 Db::name('package')->where('id', 'in', $tempPcgArr)->setField('surplus', 0);
// setField 方法返回影响数据的条数,没修改任何数据字段返回 0
--------------------------------------------------------------------------------
$count = Db::name('task_'.$taskinfo['number'])->where('status', 0)->count();
--------------------------------------------------------------------------------
Db::query('select * from think_user where id=?',[8]);//原生查询
Db::execute('insert into think_user (id, name) values (?, ?)',[8,'thinkphp']);//原生写入
config是一个单独的数据库配置,支持数组和字符串,也可以是一个数据库连接的配置参数名。
Db::connect($config)->query('select * from think_user where id=:id',['id'=>8]);
--------------------------------------------------------------------------------
sql调试
$result = Db::table('think_user')->fetchSql(true)->find(1);
--------------------------------------------------------------------------------