para2x
Member
سلام به دوستاي خوبم
آقا من يه كد دارم كه از ديتا بيس بك اپ مي گيره .فقط مشكلش اينه كه بعد كه بكاپ مي گيريم و فايلش رو تويه ديتابيس لود مي كنم نوشته ها رو اينجوري نشون مي ده ؟؟؟؟؟؟
حالا كسي ميدونه اين چه مشكلي داره ؟
اينم كد:
راستي خودم هم اين كوئري تبديل به utf-8 رو گذاشتم بعضي جاهاش ولي بازم ....
اينو
ممنون مي شم كمك كنين
آقا من يه كد دارم كه از ديتا بيس بك اپ مي گيره .فقط مشكلش اينه كه بعد كه بكاپ مي گيريم و فايلش رو تويه ديتابيس لود مي كنم نوشته ها رو اينجوري نشون مي ده ؟؟؟؟؟؟
حالا كسي ميدونه اين چه مشكلي داره ؟
اينم كد:
PHP:
<?php
/* backup.php
Create a zipped output of all/selected table in a database */
//////////////////////// CONFIG /////////////////////////////////
// db settings
//Database name/
$mdb = "";
//MySQL Host name/
$mhost = "";
//MySQL Username/
$muser = "";
//MySQL Password/
$mpass = "";
/* Tables. If you want to back up all tables, leave the array empty. Otherwise the format is:
$tables = array("table_1","table_2",..."table_n")*/
$tables = array();
// Name of directory that will store the backups. No slashes!
$pathname = "backups";
//Email settings
$to = "You <you@your_domain.invalid>";
$from = "From: Quirm Backup Manager <server@your_domain.invalid>";
// Do you want an email if there is a problem?
$email = "no";
//////////////////////// CONFIG ENDS /////////////////////////////////
$timestamp = '.'.date('d-m-Y');
$absolute_path = dirname(__FILE__).DIRECTORY_SEPARATOR.$pathname.DIRECTORY_SEPARATOR;
$filename = $mdb.$timestamp.".sql.gz";
$temp = $mdb.".sql.gz";
$today = date('D, F j, Y \a\t H:i:s');
// Test to see if we have access to the gzopen function
$gz = (bool) function_exists('gzopen');
// check backup directory exists. If not, send an error message
if(!is_dir($pathname) || substr(sprintf('%o', fileperms($pathname)), -4) !="0777") {
$subject = "DB Backup: Directory Missing";
$err = "Directory '".$pathname."' either doesn't exist or you need to chmod it to 777\n";
echo $err;
$mail_body = $err;
if($email == "yes") mail($toHeader,$subject,$mail_body,$fromHeader);
exit;
}
$fileheader = "# mySQL backup ".$today."\n# Server: ".$_SERVER['SERVER_NAME']."\n# Database: ".$mdb."\n\n";
ob_start();
flush();
//////////////////////////////////////////////////////////////////////////
$connect = mysql_connect($mhost,$muser,$mpass);
$msg=$error="";
if (!$connect) {
$error="<p>Unable to connect to the database server at this time.</p>\n";
$msg = "\nFailed to connect to database server in file ".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."\n".mysql_error();
}
$db_selected = mysql_select_db($mdb,$connect);
if (!$db_selected) {
$error ="<p>Unable to use ".$mdb." : ".mysql_error()."</p>\n" ;
$msg = "\nUnable to use database ".$mdb." in file ".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."\n".mysql_error();
}
mysql_query("SET CHARACTER SET 'UTF-8'", $connect);
if($msg !="" && $notify == "yes") {
$subject = "DB Backup Error";
$mail_body = $msg;
// Send the mail
mail($toHeader,$subject,$mail_body,$fromHeader);
}
//////////////////////////////////////////////////////////////////////
unset($backup);
$backup = "";
$tab_status = mysql_query("SHOW TABLE STATUS");
if (!$tab_status) {
echo "Error: Could not show table status! \n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while($all = mysql_fetch_assoc($tab_status)) {
$tbl_stat[$all['Name']] = $all['Auto_increment'];
}
if(count($tables) == 0) {
// we want to backup all tables
$tables = mysql_query("SHOW TABLES FROM $mdb");
if (!$tables) {
echo "Error: Could not list tables! \n";
echo "MySQL Error: " . mysql_error();
exit;
}
while($tabs = mysql_fetch_row($tables)) {
$backup .= PrintOut($backup,$tabs[0],$tbl_stat[$tabs[0]]);
}
}
else {
// we want to backup selected tables
foreach($tables as $table) {
$show_query ="SHOW TABLE STATUS FROM $mdb LIKE '$table'";
$show = mysql_query($show_query);
if (!$show) {
echo "Error: Could not show ".$table." \n";
echo "MySQL Error: ". mysql_error()."\n";
exit;
}
while($tabs = mysql_fetch_row($show)) {
$backup .= PrintOut($backup,$tabs[0],$tbl_stat[$tabs[0]]);
}
}
}
// everything looks ok, so create a temp file
if (($gz && ($zp = gzopen($absolute_path.$temp, 'wb'))) || (!$gz && ($fp = fopen($absolute_path.$temp, 'wb')))) {
if ($gz) gzwrite($zp, $fileheader, strlen($fileheader));
else fwrite($fp, $fileheader, strlen($fileheader));
}
if ($gz) {
gzwrite($zp, $backup);
gzwrite($zp, "\n\n--\n-- Backup complete! --\n--\n");
gzclose($zp);
}
else {
fwrite($fp, $backup);
fwrite($fp, "\n\n--\n-- Backup complete! --\n--\n");
fclose($fp);
}
$final = $absolute_path.$filename;
// if we already have a backup today, remove it
@unlink($final);
// create the final backup file
rename($absolute_path.$temp, $final);
if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') touch($final);
echo "Backup created";
ob_end_flush();
/************************************************************************/
function PrintOut($output,$tbl,$stats) {
$output = "--\n-- Table structure for `$tbl`\n--\n\nCREATE TABLE `$tbl` ( ";
$res = mysql_query("SHOW CREATE TABLE $tbl");
while($al = mysql_fetch_assoc($res)) {
$str = str_replace("CREATE TABLE `$tbl` (", "", $al['Create Table']);
$str = str_replace(",", ",", $str);
$str2 = str_replace("`) ) TYPE=MyISAM ", "`)\n ) TYPE=MyISAM ", $str);
if ($stats) $str2 = $str2." AUTO_INCREMENT=".$stats;
$output .= $str2.";\n\n";
}
$output .= "-- \n-- Dumping data for table `".$tbl."`\n-- \n\n";
$data = mysql_query("SELECT * FROM $tbl");
while($dt = mysql_fetch_row($data)) {
$output .= "INSERT INTO `$tbl` VALUES('$dt[0]'";
for($i=1; $i<sizeof($dt); $i++) {
$dt[$i] = mysql_real_escape_string($dt[$i]);
$output .= ", '$dt[$i]'";
}
$output .= ");\n";
}
$output .= "\n-- --------------------------------------------------------\n\n";
return $output;
}
/************************************************************************/
/************************************************************************/
?>
راستي خودم هم اين كوئري تبديل به utf-8 رو گذاشتم بعضي جاهاش ولي بازم ....
اينو
PHP:
mysql_query("SET CHARACTER SET 'UTF-8'", $connect);
ممنون مي شم كمك كنين