我有一个数据库,里面装满了MSSQL Windows-1253的数据,想要传入一个普通的opencart数据库(UTF-8)。 使用下面的代码,所有的英文字符都可以通过,但里面的希腊字符就像那样Ä××ÔÕËÉÄÉ
是否建议如何将数据从一个数据库更正为另一个数据库?
<? header('Content-Type: text/html; charset=UTF-8');
include("config.php");
$db1 = mysql_connect(DB_HOSTNAME, 'dbuser', 'dbpass');
mysql_select_db('dbname', $db1) or die(mysql_error());
mysql_query( "SET NAMES utf8", $db1);
mysql_query( "SET CHARACTER SET utf8", $db1);
mysql_query('SET character_set_results=utf8', $db1);
mysql_query('SET names=utf8', $db1);
mysql_query('SET character_set_client=utf8', $db1);
mysql_query('SET character_set_connection=utf8', $db1);
mysql_query('SET character_set_results=utf8', $db1);
mysql_query('SET collation_connection=utf8_general_ci', $db1);
mysql_set_charset('utf8',$db1);
$db2 = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
mysql_select_db(DB_DATABASE, $db2) or die(mysql_error());
mysql_query( "SET NAMES utf8", $db2);
mysql_query( "SET CHARACTER SET utf8", $db2);
mysql_set_charset('utf8',$db2);
//Update Categories
$q = mysql_query("SELECT * FROM prdcategories", $db1) or die(mysql_error());
$i = 0;
echo "<h2>Updating categories</h2>";
echo "<ul>";
while($r = mysql_fetch_assoc($q)) {
$query = mysql_query("SELECT * FROM prdtypes WHERE id ='".$r['id']."'", $db1) or die(mysql_error());
$result = mysql_fetch_assoc($query);
$check = mysql_query("SELECT * FROM category_description WHERE name='".$r['en']."'", $db2) or die(mysql_error());
if(mysql_num_rows($check) == '0') {
echo "<li><font color='blue'>Importing category <b>".$r['en']."</b>!</font>";
if($i < 9) { $top = '1'; } else { $top = '0'; }
mysql_query("INSERT INTO category VALUES ('', '', '0', $top, '1', '0', '1', NOW(), NOW())", $db2) or die(mysql_error());
$id = mysql_insert_id();
mysql_query("INSERT INTO category_description VALUES ($id, '1', '".$r['en']."', '', '', '')", $db2) or die(mysql_error());
mysql_query("INSERT INTO category_description VALUES ($id, '2', '".$r['el']."', '', '', '')", $db2) or die(mysql_error());