<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php
	//数据库表维护，注意：首先备份数据库，然后用本程序。32 行数据库操作注释了
	
	session_start(); 

	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	
		
	$opendb=new mydb();
	include('inc/char_set.php');
	$i=0;
	

	$tableResult = mysql_query("show tables"); 
	while   ($row   =   mysql_fetch_row($tableResult)) {    
		$tablename= $row[0];
		$sqlcolumns   ="show columns in  ".$tablename." "; 
		$querycolumns   = $opendb->query($sqlcolumns); 

		while($rowscolumns=mysql_fetch_assoc($querycolumns))
		{		
			$fieldname=$rowscolumns['Field']; 
			if($fieldname=="Num"){
				$rescolumns="ALTER TABLE    `".$tablename."` CHANGE  `Num`  `Num` INT( 8 ) NULL DEFAULT  '1' "; //ALTER TABLE  `ls_certificate` CHANGE  `Num`  `Num` INT( 4 ) NULL DEFAULT  '1'
				//echo  $rescolumns;
				//$rescolumnsResult = $opendb->query($rescolumns); 
			   
				if($rescolumnsResult){
					  echo "<br/>".$row[0]." ok  改了 $i 个<br/>";
					  $i++;
				}
				else{echo "<br/>".$row[0]." ERROR <br/><br/>"; }
			}
		
		}
		
	}
				
/*  */
	echo "<br/>完成： $i  张表 ";

?>

<? 	//for($j=1;$j<=2;$j++)

 /*
			include('inc/conn.php');
			
			$opendb=new mydb();
			include('inc/char_set.php');


		$i=0;
		
				$tableResult = mysql_query("show tables"); 
				while   ($row   =   mysql_fetch_row($tableResult)) {   //删除多个ls_site_b2b表
					if(substr($row[0],0,11)=='ls_site_b2b'){
						
					//	$del_sql="ALTER TABLE ".$row[0]."  MODIFY COLUMN    `siteName` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL  "; ALTER TABLE `".$row[0]."` CHANGE `right` `right1` INT( 2 ) NOT NULL COMMENT '权重'
					// ALTER TABLE `ls_site_b2b` CHANGE `message` `message` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL 
					//	$del_sql=" ALTER TABLE `".$row[0]."` CHANGE `right` `right1` INT( 2 ) NOT NULL COMMENT '权重' ";
					// $del_sql=" ALTER TABLE `".$row[0]."`  CHANGE `message` `message` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL  ";  ALTER TABLE  `ls_seoitems_init` ADD  `seoBrief` TEXT NOT NULL COMMENT  '客户优化显示' AFTER  `alert`
					$del_sql="ALTER TABLE `".$row[0]."` ADD  `help` TEXT NOT NULL COMMENT  '帮助' AFTER  `memo` ";
					
					
						$del_query=$opendb->query($del_sql);
						echo $row[0]."ok,<br/>   ";
						$i++;
					}
					
				}
	
		//$tableResult   =   mysql_list_tables($dbname); 
		echo "<br/>完成： $i  张表 ";
 
 */
 
 /* 增加字段
 			include('inc/conncn.php');
			
			$opendb=new mydb();
			include('inc/char_set.php');
			$i=0;
			$j=0;
			$addfield="seoBrief";
		
				$tableResult = mysql_query("show tables"); 
				while   ($row   =   mysql_fetch_row($tableResult)) {    
					if(substr($row[0],0,11)=='ls_seoitems'){
							  
						  //	$del_sql="ALTER TABLE ".$row[0]."  MODIFY COLUMN    `siteName` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL  "; ALTER TABLE `".$row[0]."` CHANGE `right` `right1` INT( 2 ) NOT NULL COMMENT '权重'
						  // ALTER TABLE `ls_site_b2b` CHANGE `message` `message` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL 
						  //	$del_sql=" ALTER TABLE `".$row[0]."` CHANGE `right` `right1` INT( 2 ) NOT NULL COMMENT '权重' ";
						  // $del_sql=" ALTER TABLE `".$row[0]."`  CHANGE `message` `message` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL  ";  ALTER TABLE  `ls_seoitems_init` ADD  `seoBrief` TEXT NOT NULL COMMENT  '客户优化显示' AFTER  `alert`
						  $rescolumns="SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT  FROM    INFORMATION_SCHEMA.COLUMNS    WHERE       table_name = '".$row[0]."' AND table_schema = 'ls_submitcn'      and  COLUMN_NAME  =  '".$addfield."'";
						  $rescolumnsResult = mysql_query($rescolumns); 
						  $allrows=mysql_num_rows($rescolumnsResult);
						   if($allrows==0)
						   {
							  $changesql=" ALTER TABLE  `".$row[0]."` ADD  `".$addfield."` TEXT NOT NULL AFTER  `ID`";
							   $changeResult = mysql_query($changesql); 
							   echo $row[0]." ok<br/>";
							   $j++;
						  }
							
 					}

						$i++;
				 
					
				}

 */	
		//$tableResult   =   mysql_list_tables($dbname); 
?>