$tables = $db->query("select table_name from information_schema.tables where table_schema=‘yuyue‘ and table_name like ‘patient_%‘ ");
for($i=0;$i<1100;$i++)
{
$arr[] = ‘patient_‘.$i;
}
foreach($tables as $tbl)
{
//var_dump($tbl);
$tbl = $tbl[‘table_name‘];
if(in_array($tbl,$arr))
{
//判断是否有字段
$sql_column = "select column_name from information_schema.columns where table_schema=‘yuyue‘ and table_name=‘{$tbl}‘ and column_name = ‘cname‘";
$res_column = $db->query($sql_column);
if(empty($res_column)){
$sql ="alter table {$tbl} add cname varchar(50) not null default ‘0‘ comment ‘所属咨询‘";
//$sql ="alter table {$tbl} drop cname ";
//echo $sql.‘<br>‘;
$res = $db->query($sql);
var_dump($tbl);
var_dump($res);
}
}
}
die;