3 删除MYSQL数据库重复数据,只保留一条数据

<?php 
	//删除重复数据,只保留一条数据
	function  deleteDupyData($db,$dbName){
		$sql	=	"SELECT `id` FROM `test` WHERE  `dbName`='{$dbName}'";
		//echo $sql;
		$result	=	$db->fetchArrs($sql);
		if(!empty($result)){
			foreach ($result as $k=>$v){
				if($k>0){
					$idStr	.=	$v[0].',';
				}	
			}
			$idStr	=	rtrim($idStr,',');
			$sql2	=	"DELETE FROM `test` WHERE `id` in (".$idStr.")";
			//echo $sql2;
			$result2	=	$db->query($sql2);
		}
		if($result2!=false){
			return true;
		}else{
			return false;
		}
	}
 
?>

Related posts:

Leave a Reply

Your email address will not be published.