今天就跟大家聊聊有关mysql big5转 utf-8的转换程式是怎么样的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
這支程式 會 dump 出 db 下的所有 insert 的 query ,
使用方法
1.
將 big5 環境的 create dump 出來 ,
然後 再將 CHARSET=latin1 或 CHARSET=big5
改成 CHARSET=utf8
然後 create 一個空的 databases + table .
2.
下載 metabase : 請參考附件
3.
convert.php
[@more@]
#!/usr/bin/php -q
<?php
set_time_limit(0) ;
############################################################################
# sql link start
############################################################################
$db_type = "mysql";
$host_name = "localhost" ;
$database_name = "heyforum_dz5" ;
$user_id = "root" ;
$user_password = "xxxxxxxxxxxx" ;
include_once("metabase/metabase_interface.php");
include_once("metabase/metabase_database.php");
$db_params=array(
"Host" =>$host_name
,"Type" =>$db_type
,"User" =>$user_id
,"Password" =>$user_password
,"IncludePath" =>"metabase/"
,"Persistent" =>0
);
############################################################################
# sql link end
############################################################################
$error=MetabaseSetupDatabase($db_params,$db);
MetabaseSetDatabase($db,$database_name);
$query ="show tables";
$db_res=MetabaseQuery($db,$query);
if(!$db_res) {
ecstart_alert_err($msg["system_err"]);
}
$rows=MetabaseNumberOfRows($db,$db_res);
MetabaseGetColumnNames($db,$db_res,$db_field_name);
if($rows)
{
for($row=1;$row<=$rows;$row++)
{
if(is_array($db_field_name)){
foreach($db_field_name as $key => $value){
$table[$row-1]=MetabaseFetchResult($db,$db_res,$row-1,$key) ;
}
}
}
}
if(is_array($table)){
foreach($table as $k => $v){
$query ="describe ".$v;
$db_res=MetabaseQuery($db,$query);
if(!$db_res) {
ecstart_alert_err($msg["system_err"]);
}
$rows=MetabaseNumberOfRows($db,$db_res);
MetabaseGetColumnNames($db,$db_res,$db_field_name);
if($rows)
{
for($row=1;$row<=$rows;$row++)
{
if(is_array($db_field_name)){
foreach($db_field_name as $key => $value){
$field[$v][$row-1]=MetabaseFetchResult($db,$db_res,$row-1,"field") ;
}
}
}
}
//print_r($field);
}
}
if(is_array($field)){
foreach($field as $k => $v){
// get field value
$query ="select * from ".$k;
$db_res=MetabaseQuery($db,$query);
if(!$db_res) {
ecstart_alert_err($msg["system_err"]);
}
$rows=MetabaseNumberOfRows($db,$db_res);
MetabaseGetColumnNames($db,$db_res,$db_field_name);
if($rows)
{
for($row=1;$row<=$rows;$row++)
{
if(is_array($db_field_name)){
foreach($db_field_name as $key => $value){
$field_value[$row-1][$key]=MetabaseFetchResult($db,$db_res,$row-1,$key) ;
}
}
$no = 0 ;
$field_str = "";
foreach($v as $fv){
if($no == 0){
$field_str .= "`".$fv."`";
}
else{
$field_str .= ",`".$fv."`";
}
$no = $no+1 ;
}
$sno = 0 ;
$field_value_str = "";
foreach($field_value[$row-1] as $fvk => $fvv){
if($sno == 0){
$field_value_str .= "'".mysql_escape_string(iconv('BIG5','UTF-8',$fvv))."'";
}
else{
$field_value_str .= ",'".mysql_escape_string(iconv('BIG5','UTF-8',$fvv))."'";
}
$sno = $sno+1 ;
}
$query = "insert into ".$k."(".$field_str.") values(".$field_value_str.");";
unset($field_value[$row-1]);
unset($field_str);
unset($field_value_str);
echo $query . "
";
//print_r($field_value);
}
}
unset($field_value);
}
}
MetabaseCloseSetup($db)
?>
4.
將 convert.php 存檔後
執行 ./convert.php > convert.sql
5. mysql database_name -uroot -p < convert.sql
好了
看完上述内容,你们对mysql big5转 utf-8的转换程式是怎么样的有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/202092.html