判断是否存在表
Schema::connection("mysql_log")->hasTable($tableName)
判断是否存在字段
Schema::connection("mysql_log")->hasColumn($tableName,'register_time')
laravel中同样的表结构合并查询
$tableNames=[];
for($i=0; $i<=$longDay; $i++){
$sqlName="sql".$i;
$date = date('Ymd',time()-$i*86400);
$tableName = "log_game_".$gameId."_".$date;
$model =new GameLoginLogModel();
$model->setTable($tableName);
if(Schema::connection("mysql_log")->hasTable($tableName) &&Schema::connection("mysql_log")->hasColumn($tableName,'register_time')){
$tableNames[]=$tableName;
$datas[$sqlName]=DB::connection("mysql_log")->table($tableName)->where(["user_id"=>$userId]);
$lastTableName =end($tableNames);
$sql =DB::connection("mysql_log")->table($lastTableName)->where(["user_id"=>$userId]);