匯入excel檔案時疏失線上求解

來源:互聯網
上載者:User
匯入excel檔案時出錯線上求解
有個關於匯入excel檔案的問題求解。。
error_reporting(0);
//匯入CSV格式的檔案
$connect=mysql_connect("localhost","root","root") or die("could not connect to database");
mysql_select_db("student",$connect) or die (mysql_error());
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $connect);
$fname = $_FILES['MyFile']['name'];
$handle=fopen("$fname","r");
while($data=fgetcsv($handle,10000,","))
{
$q="insert into timetable (cid,week,jieci,name,teacher) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
mysql_query($q) or die (mysql_error());

}
fclose($handle);
$fname = $_FILES['MyFile']['name'];
$do = copy($_FILES['MyFile']['tmp_name'],$fname);
if ($do)
{
echo"匯入資料成功
";
} else {
echo "";
}


當我第一次提交之後匯入的
excel會在檔案夾下面 但是資料庫裡面沒有


我繼續提交之後提示:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\x87.\xC76\x90\xF4\x03\x14kl\x8B\xD8\x92\xD0L\xD2\xE4\xEF;v\x16J\xC8\x82i\xA0\xB' at line 1
這該怎麼搞?明天要交作業了 求指導。

分享到:


------解決方案--------------------
"\x87.\xC76\x90\xF4\x03\x14kl\x8B\xD8\x92\xD0L\xD2\xE4\xEF;v\x16J\xC8\x82i\xA0\xB"
顯然不是 utf-8 編碼的資料
------解決方案--------------------
csv檔案另存新檔UTF-8編碼的文檔。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.