Gnuboard backup rehearsal practice
After receiving the backup carefully (??) to convert the existing DB from EUC-KR to UTF8,
I opened it with editplus,Including characters that can be lost in encodingIt is said to be,
Ignore it, change it to UTF8 and IMPORT… . Damn ㅠㅠ not because of the broken letters
Search in a hurry ~~~~ In the end, I can't see the method ..
(This is a case where you can't give you all the options to –DEFAULT-CHARACTER-SET when dumping.)
Inevitably discovers the following source, modify it to suit your taste (UTF8 conversion, select your desired table)
Previous confirmation complete !!!!- I'm tired of relocation too.
[PHP]
$mysql_host = '********';
$mysql_db = '********';
$mysql_user = '********';
$mysql_pass = '********';
$fileName = 'db-backup';
$extention = "sql";
// 필요한 테이블만~
$select[] = 'g4_board';
$select[] = 'g4_board_file';
$select[] = 'g4_board_good';
$select[] = 'g4_board_new';
$select[] = 'g4_config';
$select[] = 'g4_group';
$select[] = 'g4_group_member';
$select[] = 'g4_write_cast';
$select[] = 'g4_write_delphibbs';
$select[] = 'g4_write_english';
$select[] = 'g4_write_girl';
$select[] = 'g4_write_gy';
$select[] = 'g4_write_humor';
$select[] = 'g4_write_module';
$select[] = 'g4_write_mypage';
$select[] = 'g4_write_notice';
$select[] = 'g4_write_poll';
$select[] = 'g4_write_qna';
$select[] = 'g4_write_skin';
$select[] = 'g4_write_talk';
$select[] = 'g4_write_temp';
$select[] = 'g4_write_temppds';
$select[] = 'g4_write_test';
$select[] = 'g4_write_tiptech';
$select[]= 'g4_write_varios';
$ all = false; // TRUE to write a complete INSERT statement
$ drop = true; // TRUE to include the Drop Table syntax
MySQL_CONNECT ($ mysql_host, $ mysql_user, $ mysql_pass) || DIE ("failed to connect to data base.");
MySQL_SELECT_DB ($ MySQL_DB) || DIE ("DB access failure");
Function Bak_getTablenames ($ DB)
{
$ results[0] = mysql_list_tables($db);
$result[1] = mysql_num_rows($result[0]);
return $result;
}
function bak_getFields($table)
{
global $all;
$result = mysql_query("show fields from $table");
$i = 0;
while($keys = mysql_fetch_array($result))
{
if(!$i) $defaultOrder = $keys[Field];
if($keys[Key] == 'PRI')
{
$orderby = $keys[Field];
break;
}
$i++;
}
if(!$orderby) $orderby = $defaultOrder;
$result = mysql_query("select * from $table order by $orderby");
$nums = mysql_num_fields($result);
if($all == true)
{
for($i=0;$i<$nums;$i++)
{
$fields[] = mysql_field_name($result,$i);
}
$fields = "(".implode(",",$fields).") ";
}
while($rows = mysql_fetch_row($result))
{
for($i=0;$i<$nums;$i++)
{
$temp = $rows[$i];
$temp = str_replace("'","''", $temp);
$temp = str_replace("","\", $temp);
$temp = str_replace("n",'n', $temp);
$temp = str_replace("r",'r', $temp);
$temp = iconv('CP949', 'UTF-8', $temp);
$insertValues[$i] = $temp;
}
$return .= "INSERT INTO $table ".$fields."values ('".implode("','",$insertValues)."');n";
}
return $return;
}
$tables = bak_getTableNames($mysql_db);
if($tables[1] > 0)
{
$ backtext = ”
# MysqlDump
# Host: “. $ Mysql_host.”
#The processed time: “.date”
# Server version: “.mysql_get_server_info ().”
# Database :` ". $ Mysql_db."
# ————————————————— - nnnnnN ”;
while($rows = mysql_fetch_row($tables[0]))
{
$chk = false;
for($i=0;$i
Leave a Reply