<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
	//把某一个webmotor数据库中的某个字符串$src替换成新字符串$obj
	session_start();
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/ls_inccode.php');
	
	require_once('inc/check.php');
	$db1="haiwaixiu.cn";
	$src="母婴生活馆"; // 被替换	 
	$obj="母婴加盟店"; //   
	
	$opendb=new mydb($db1);
	require_once('inc/char_set.php');
  	$replstr ="";  
 	$allupdate=0;
	$j=0;
	
if($_POST['submitaddlang']=="确定" ){ 
	
	$includetable=array(  ); // 必须包含的表
	// $skiptitle=array("ID","Num","enable" ,"clickNum", "grade", "suffStr" ); // 与这些关键字相同的字段跳过,ls
	$skiptitle1=array( 'catid' ,  'siteid' ,  'module' ,  'type' ,  'modelid' ,  'parentid' ,  'arrparentid' ,  'child' ,'letter' ,  'arrchildid' ,    'style' ,    'items' ,  'hits' ,  'setting' ,  'listorder' ,  'ismenu' ,  'sethtml' ,    'usable_type' 
 ); // 与这些关键字相同的字段跳过,phpcms
	$skiptitle2= explode(",","userid,id,username,md5,ip,password,qq,logo,sessionid,price,cid,size") ;
	$skiptitle=array_merge($skiptitle1,$skiptitle2); 
	//var_dump($skiptitle);

	$skiptable= explode(",","ld_shop_orders,ls_watermark,ls_transslow,ls_transfast,partimages,ls_ver,ls_transslow,ls_statistics,ls_propic,ls_pro_feedback,ls_log") ; // 跳过的表
	
		$j=0;
		$alltables="";
		$sqltable="show table status  ";
			$querytable=$opendb->query($sqltable);
			while($rowstable=mysql_fetch_assoc($querytable))
		  	{				
				$tablename=trim($rowstable['Name']);
				if($tablename=="") continue; // ||!strin($tablename,$includetable
				if(!strin($tablename,$skiptable))
				{ 
					$alltables.=$tablename." , ";
					
					 $sqlcolumns   ="show columns in  ".$tablename." "; 
					  $querycolumns   = $opendb->query($sqlcolumns); 
					 // echo $tablename."  ";

					  while($rowscolumns=mysql_fetch_assoc($querycolumns))
					  {		
						  $j++;
						  $fieldname=$rowscolumns['Field'];
						  if($fieldname=="")continue;
                          
						  if(!strin($fieldname,$skiptitle)&&$rowscolumns['Type']!="time" &&$rowscolumns['Type']!="date" &&$rowscolumns['Type']!="datetime"&&$rowscolumns['Type']!="int"&&$rowscolumns['Type']!="float" &&$rowscolumns['Type']!="timestamp" &&$rowscolumns['Type']!="double"   )
						  {
							  $sql11="select * from ".$tablename."  ";
							  $querytable11=$opendb->query($sql11);
							  while($rowsrepl=mysql_fetch_assoc($querytable11))
							  {				
							  	 //echo $tablename."==".$rowsrepl['ID']."==".$rowsrepl[$fieldname]."--".$fieldname."<br/>";

							  	  if(!(strpos($rowsrepl[$fieldname],$src)===false)){	
										$updatesql="update `$tablename` set `$fieldname` = replace( `$fieldname` ,'".$src."','".$obj."' )  WHERE `ID`= ".$rowsrepl[ID]." ";
								//echo  $updatesql."<br/>";
										$updatequery    = $opendb->query($updatesql); 
										if($updatequery) $replstr.= $rowsrepl[ID]."---".$tablename ."---".$fieldname." 替换 ".$obj." <br/> ";
										 $allupdate++;
								  }
								 
								
							  }
							  $j++; 
								//	$replstr.= $tablename ."-".$fieldname." <br/> ";
								 
                      	  }
					  }   
				}
				 
			}

}
$ls_msg.="<br/>".$replstr."<br/>替换".$allupdate."表，扫描".$j."表";
	$transsqlinit="CREATE TABLE temp4 AS 
SELECT  `a`.id, `a`.truetime, `a`.title, `c`.classpagekey,    `b`.newstext, `c`.classname, `c`.intro	  
FROM phome_ecms_news as `a`
LEFT JOIN phome_ecms_news_data_1 as `b` ON `a`.id = `b`.id
LEFT JOIN phome_enewsclass as `c` ON `b`.classid = `c`.classid

UPDATE ls_article  as `a`   LEFT JOIN ls_functioncates as `b` ON `b`.cateName = `a`.cateName SET a.functionName =b. functionName

UPDATE ls_article SET articleText = replace(articleText ,'\\\\','')

UPDATE ls_article  as `a`   LEFT JOIN temp4 as `b` ON `b`.id = `a`.id SET a.articleDate =FROM_UNIXTIME(b.truetime)  
UPDATE ls_article  as `a`   LEFT JOIN temp4 as `b` ON `b`.id = `a`.id SET a.articleText =CONCAT(a.articleText ,'<br/><img src=\" ',b.titlepic  ,'\" />')

ALTER TABLE  `temp4` CHANGE  `title`  `articleTitle` CHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT  ''

ALTER TABLE  `temp4` ADD  `cateName` VARCHAR( 50 ) NOT NULL AFTER  `functionName` ,
ADD  `description` VARCHAR( 150 ) NOT NULL AFTER  `keywords`

 
";
    

?>

<link href="css/admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/style2.css" />
<script language="JavaScript" src="js/jquery.js"></script>
<script language="JavaScript" src="js/ls.js"></script>
<title>数据库内容替换</title>
</head>
<body>
<div> 
<?= $ls_msg ?>		  
<form id="adfastmanual" name="adfastmanual" method="post" enctype="multipart/form-data"  action="<?php echo $PHP_SELF;?>">
        
    <a href='http://192.168.2.20/phpMAd/sql.php?db=<?=$db1?>&table=<?=$selecttable?>' target='_blank' ></a>
    <div align="center">
     <table width="80%" border="0" cellspacing="5">
         <tr>
           <td width="100%" align="center"   valign="top" style="padding-left:0%"><a href='http://192.168.2.20/phpMAd/sql.php?db=<?=$db1?>&amp;table=<?=$selecttable?>' target='_blank' >【
<?=$db1?>】</a></td>
         </tr>
           </table>
              <p>&nbsp;</p>
              <p>replace
                '<?=$src?>' with '<?=$obj?>'
                
              </p>
              <p>&nbsp;</p>
               <p></button>

                 <button name="submitaddlang" type="submit" value="确定" onClick=" "/>                  
                 确定</button>
                  
                  <button type="button" name="button" id="button" value="打开<?=$db1?>"  onclick='window.open("http://192.168.2.20/phpMAd/index.php?db=<?=$db1?>","_blank");'/>                       
                打开<?=$db1?></button>
             </p>
               <p><br />
               </p>
</div>
       
        </form>   

      </p></td>
       
  </tr>
</table>
</div>
</body>
</html>