Home > php教程 > PHP源码 > 修复mysql所有的表

修复mysql所有的表

PHP中文网
Release: 2016-05-23 16:37:14
Original
1096 people have browsed it

php代码:

<?php
 class tools{
 	/**
 	 * 
 	 * @param string $usr 用户名
 	 * @param string $pwd 密码
 	 * @param string $dbname 数据库名称
 	 * @param string $charset 字符集
 	 */
 	function repair_mysql_tables($usr,$pwd,$dbname,$charset="utf8"){
 	
 		$dsn="mysql:host=127.0.0.1;port=3306;dbname=".$dbname;
 		try{
 			$conn=new PDO($dsn ,$usr,$pwd,array(PDO::ATTR_PERSISTENT=>true));
 			$conn->exec("SET NANMES".$charset);
 		}catch(PDOException $e){
 		
 			echo "Error!:".$e->getMessage()."<br/>";
 			die(&#39;db connect failed ...&#39;);
 		}
 		$arr=$conn->query("show tables");
 		$arr1=$arr->fetchAll(PDO::FETCH_ASSOC);
 		foreach ($arr1 as $a){
 			foreach ($a as $a1){
 				$conn->query("repair table  ".$a1);
 				echo "table :<span style=&#39;color:red;&#39;>".$a1."</span> is repair..<br/>";
 			}
 		}
 		echo "task complete !";
 	}	
 }
 //调用方法
   $too=new tools();
   $too->repair_mysql_tables("root", "", "fangjia");
 ?>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template