【问题标题】:Importing data from Excel to MySQL showing text in different language将数据从 Excel 导入 MySQL,以不同语言显示文本
【发布时间】:2020-02-24 18:55:39
【问题描述】:

我正在尝试使用 PHP 将数据从 Excel 导入 MySQL。我正在使用的代码导入数据,但语言很奇怪。

以下是PHP代码:

<?php

    include_once("conn.php");
    $filename= "Financial Sample.xlsx";
    $file = fopen($filename, "r");

    $count = 0;                                         // add this line
    while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
    {
        //print_r($emapData[0]);
        //exit();
        $count++;                                      // add this line

        if($count>1){                                  // add this line

        //echo html_entity_decode("žūų");

        //echo json_encode($emapData[0]);
         $insert_q = "INSERT into questions(q_describe) values ('$emapData[0]')";
        if($query_q=$mysqli->query($insert_q))
        {
            $final=array();
            $final['status']="success";
            $final['message']="Inserted Successfully";
        }
        else
        {
            $er = $mysqli->error;
             $final['status']=$er;
            $final['message']="Error";
        } 

        echo json_encode($final);
        }                                              // add this line
    } 
    fclose($file);
?>

一旦导入,数据在 phpMyAdmin 中显示如下:

实际Excel如下图:

我哪里错了?

编辑

显示我的表的结构:

【问题讨论】:

  • 对我来说似乎是一个编码错误
  • 我该如何纠正?
  • 什么是$mysqli?它是如何实例化的?

标签: php mysql excel file import


【解决方案1】:

如果您查看表的结构,您会发现两个字段:编码和排序规则。

确保它们分别设置为 cp1252 West European 和 latin1_swedish_ci。

【讨论】:

  • 我已经编辑了问题并显示了我的表格结构,我可以看到排序规则,但我在任何地方都看不到编码
猜你喜欢
  • 2013-01-11
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 2017-01-13
  • 2014-04-11
  • 1970-01-01
  • 1970-01-01
  • 2011-10-15
相关资源
最近更新 更多