php将文本文件插入mysql编码

php将文本文件插入mysql编码,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我必须将数据从.txt文件导入mySQL数据库 当我用记事本打开txt文件时,该文件是用DOS/Windows ANSI编码的。 当我用AkelPad打开它时,我得到的信息是该文件是用1253 ANSI希腊文编码的 我用下面的代码导入数据 $myFile = "Bill.txt"; $fh = fopen($myFile, 'r'); $theData1 = fread($fh, filesize($myFile)); $theData = str_replace("'","#",$theDat

我必须将数据从.txt文件导入mySQL数据库

当我用记事本打开txt文件时,该文件是用DOS/Windows ANSI编码的。 当我用AkelPad打开它时,我得到的信息是该文件是用1253 ANSI希腊文编码的

我用下面的代码导入数据

$myFile = "Bill.txt";
$fh = fopen($myFile, 'r');
$theData1 = fread($fh, filesize($myFile));
$theData = str_replace("'","#",$theData1);
$theData = iconv('cp1253','UTF-8',$theData);
$data = (filesize($myFile))/156;
fclose($fh);
$line = 0;

mysql_query("TRUNCATE Bill");
for ($counter = 1; $counter <= $data; $counter++) {
  $Barcode[counter] = substr($theData, ($line+0), 10);
  $BuildingCode[counter] = substr($theData, ($line+10), 5);
  $BuildingAddress[counter] = substr($theData, ($line+14), 40);
  $FlatName[counter] = substr($theData, ($line+54), 50);
  $FlatDescription[counter] = substr($theData, ($line+104), 8);
  $EntrySeason[counter] = substr($theData, ($line+112), 23);
  $Period[counter] = substr($theData, ($line+135), 11);
  $Amountint = substr($theData, ($line+146), 7);
  $Amountdec = substr($theData, ($line+153), 2);
  $Amount[counter] = $Amountint.'.'.$Amountdec;

  mysql_query("INSERT INTO Bill (Id, Code, Address, Name, Description, EntrySeason, Period, Revenue) 
  VALUES ('$Barcode[counter]', '$BuildingCode[counter]', '$BuildingAddress[counter]', '$FlatName[counter]', '$FlatDescription[counter]', '$EntrySeason[counter]', '$Period[counter]', '$Amount[counter]')");

  $line = $counter * 156;
}
当我用代码读取上面的数据时

$query = "SELECT * FROM Bill ORDER BY Id ASC"; 
$result = mysql_query($query) or die(mysql_error());
$i=0;
while ($row=mysql_fetch_array($result)){
$i=$i+1;
echo $i." - ".$row['Id']. " - ". $row['Code']. " - ". $row['Address']. " - ". $row['Name']. " - ". $row['Description']. " - ". $row['EntrySeason']. " - ". $row['Period']. " - ". $row['Revenue'].'<br>';
我收到希腊字母。当我用phpmyadmin检查db时,所有的希腊条目都是这样的

如果我尝试将mysql的入口插入sqlite,字母是这些


我哪里错了?

有几件事可能是错的

1您确定您正在试图保存数据的数据库中使用UTF-8数据库、表、列吗

2是否运行mysql\u查询集名称utf8;在对数据库运行选择/更新之前

如果两个都做对了,那么我建议您更详细地调试它


3尝试在txt文件中指定一个字符,尝试在iconv函数前后回显ord$str{xxx},并检查二进制数据是否真的正确编码为UTF-8

我尝试了以下我从我的txt回第一封信的ord,我收到208。在iconv iconv‘CP1253’、‘UTF-8’、$theData之后;我收到206。。。你要做什么?正确的字符是什么。应该是206还是208?当你在ord中再次尝试从数据库中获取这些信息时,你会得到什么?