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

修复mysql所有的表

PHP中文网
PHP中文网Original
2016-05-23 16:37:141126browse

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");
 ?>
Statement:
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
Previous article:php 压缩图片方法Next article:php ping端口