how to export mysql data from latin to utf8

how to export mysql data from latin to utf8

<?php
echo "start...";
$outputfile= "OUTPUT.sql";
$DB_HOST="localhost";
$DB_USER="enaaa";
$DB_PASS="adfsda";
$DB_DBNAME='safds';

$DB_TABLE[]="g2_AccessMap";
$DB_TABLE[]="g2_AccessSubscriberMap";
$DB_TABLE[]="g2_AlbumItem";
$DB_TABLE[]="g2_AnimationItem";
$DB_TABLE[]="g2_CacheMap";
$DB_TABLE[]="g2_ChildEntity";
$DB_TABLE[]="g2_Comment";
$DB_TABLE[]="g2_DataItem";
$DB_TABLE[]="g2_Derivative";
$DB_TABLE[]="g2_DerivativeImage";
$DB_TABLE[]="g2_DerivativePrefsMap";
$DB_TABLE[]="g2_DescendentCountsMap";
$DB_TABLE[]="g2_Entity";
$DB_TABLE[]="g2_ExifPropertiesMap";
$DB_TABLE[]="g2_ExternalIdMap";
$DB_TABLE[]="g2_FactoryMap";
$DB_TABLE[]="g2_FailedLoginsMap";
$DB_TABLE[]="g2_FileSystemEntity";
$DB_TABLE[]="g2_Group";
$DB_TABLE[]="g2_ImageBlockCacheMap";
$DB_TABLE[]="g2_ImageBlockDisabledMap";
$DB_TABLE[]="g2_Item";
$DB_TABLE[]="g2_ItemAttributesMap";
$DB_TABLE[]="g2_Lock";
$DB_TABLE[]="g2_MaintenanceMap";
$DB_TABLE[]="g2_MimeTypeMap";
$DB_TABLE[]="g2_MovieItem";
$DB_TABLE[]="g2_PermissionSetMap";
$DB_TABLE[]="g2_PhotoItem";
$DB_TABLE[]="g2_PluginMap";
$DB_TABLE[]="g2_PluginPackageMap";
$DB_TABLE[]="g2_PluginParameterMap";
$DB_TABLE[]="g2_RatingCacheMap";
$DB_TABLE[]="g2_RatingMap";
$DB_TABLE[]="g2_RecoverPasswordMap";
$DB_TABLE[]="g2_Schema";
$DB_TABLE[]="g2_SequenceId";
$DB_TABLE[]="g2_SequenceLock";
$DB_TABLE[]="g2_SessionMap";
$DB_TABLE[]="g2_TkOperatnMap";
$DB_TABLE[]="g2_TkOperatnMimeTypeMap";
$DB_TABLE[]="g2_TkOperatnParameterMap";
$DB_TABLE[]="g2_TkPropertyMap";
$DB_TABLE[]="g2_TkPropertyMimeTypeMap";
$DB_TABLE[]="g2_UnknownItem";
$DB_TABLE[]="g2_User";
$DB_TABLE[]="g2_UserGroupMap";

$fp=fopen($outputfile, "w+");
if(!$fp){
 echo "Can not open file for writing.\n";
 exit;
}

$dbcon=mysql_connect($DB_HOST, $DB_USER, $DB_PASS);
mysql_query("SET NAMES utf8", $dbcon);
mysql_select_db($DB_DBNAME, $dbcon);

foreach($DB_TABLE as $tableId=>$tableName){
 $sqlstr="SELECT * FROM $tableName ";
 //echo $sqlstr;
 $rs=mysql_query($sqlstr, $dbcon);
 //$NAMESTR="SET NAMES utf8;\r\n\r\n";
 //fwrite($fp, $NAMESTR, strlen($NAMESTR));
 //echo "rs=" . $rs;

 while($rsrow=mysql_fetch_row($rs)){
 $i_sqlstr="INSERT INTO $tableName VALUES(";
 foreach($rsrow as $rid=>$rval){
 //echo $rval;
 $rsrow[$rid]= $rval;//iconv("BIG5", "UTF-8", $rval);
 if(strval($rid)=="0")
 $i_sqlstr.="'".addslashes($rsrow[$rid])."'";
 else
 $i_sqlstr.=", '".addslashes($rsrow[$rid])."'";
 }
 $i_sqlstr.=");\r\n\r\n";
 echo $i_sqlstr;
 fwrite($fp, $i_sqlstr, strlen($i_sqlstr));
 }
 mysql_free_result($rs);
}
mysql_close($dbcon);
fclose($fp);
exit;
?>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 8 + 14 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)