Để chuyển DB hiện đang sử dụng từ euc-kr sang utf8, sau khi cẩn thận (??) sao lưu
mở bằng editplus thì thấy thông báo có chứa ký tự có thể bị mất với bảng mã hiện tại,
thôi cứ bỏ qua rồi đổi sang UTF8 và Import …. Chết tiệt ㅠㅠ không được vì các ký tự bị lỗi
tìm kiếm gấp~~~~ cuối cùng vẫn chẳng thấy cách nào..
(Trường hợp như thế này, dù khi dump đã thêm đủ tùy chọn, kể cả –default-character-set, vẫn không được ㅠㅠ)
Đành vậy, tìm thấy đoạn mã dưới đây rồi sửa lại theo ý mình (chuyển đổi UTF8, chọn bảng mong muốn)
Đã xác nhận chuyển đổi xong!!!! – Chuyển dữ liệu đúng là phiền phức, lại còn mệt nữa ㅠㅠ
[PHP]
$mysql_host = '********';
$mysql_db = '********';
$mysql_user = '********';
$mysql_pass = '********';
$fileName = 'db-backup';
$extention = "sql";
// Chỉ những bảng cần thiết~
$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 nếu muốn tạo câu lệnh Insert đầy đủ
$drop = true; // true nếu muốn thêm câu lệnh drop table
mysql_connect( $mysql_host, $mysql_user, $mysql_pass ) || die("Không thể kết nối với cơ sở dữ liệu.");
mysql_select_db( $mysql_db ) || die("Kết nối DB thất bại");
function bak_getTableNames($db)
{
$result[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
# Máy chủ: “.$mysql_host.”
# Thời gian xử lý: “.date(‘Y năm n tháng j ngày H giờ i phút’).”
# Phiên bản máy chủ: “.mysql_get_server_info().”
# Cơ sở dữ liệu: `”.$mysql_db.”`
# ——————————————————–nnnnn”;
while($rows = mysql_fetch_row($tables[0]))
{
$chk = false;
for($i=0;$i
[/PHP]



