Home >php教程 >PHP源码 >批量操作数据库表

批量操作数据库表

PHP中文网
PHP中文网Original
2016-05-25 17:05:331293browse

批量操作数据库表

<?php
	mysql_connect(&#39;localhost&#39;,&#39;root&#39;,&#39;123456&#39;); 
	mysql_select_db(&#39;china&#39;);  
        $rs=mysql_query(&#39;show tables&#39;); 


	while($arr=mysql_fetch_array($rs)){     
		$tf=strpos($arr[0],&#39;main_&#39;);  
		$newt=explode(&#39;main_&#39;,$arr[0]);
		
		if($tf===0){    
			//修改表名
			$ft=mysql_query("rename table $arr[0] to $newt[1]");     
			
			//删除表
			//$sql = &#39;drop table zt_&#39;.$newt[1];
			//$ft=mysql_query($sql);  

			
			if($ft){           
				echo "$arr[0] 修改成功 $newt[1]
";     
				//echo "$arr[0] 删除成功 $newt[1]
";     				
			}        
		}  

	}  
	

                   

 以上就是批量操作数据库表的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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