<?php $dbi = new DbMysql; $dbi->dbh = ‘mysql://root:[email protected]/coffeetest‘; $map = array(); $dbi->fetchMap("SHOW TABLES", $map); $tables = array_keys($map); // 找出含有cid字段的表 $cid_tables = array(); for($j=0; $j<count($tables); $j++){ $map = array(); $dbi->fetchMap("DESCRIBE ".$tables[$j], $map); foreach($map as $k=>$v){ if($k==‘cid‘) { $cid_tables[] = $tables[$j]; } } } // 找出cid=0的数据并修复 $cid = 1; $cid0_tables = array(); for($j=0; $j<count($cid_tables); $j++){ $sql = "SELECT COUNT(*) FROM ".$cid_tables[$j]." WHERE cid = 0"; $count = $dbi->getval($sql, 0); if($count>0) $cid0_tables[$cid_tables[$j]] = $count; } foreach($cid0_tables as $k=>$v){ echo("\t".$k."=".$v."\n"); $sql = "UPDATE ".$k." SET cid = ".$cid." WHERE cid = 0"; $dbi->execute($sql); } ?>
原文地址:https://www.cnblogs.com/coffee_cn/p/8994353.html
时间: 2024-11-02 22:46:52