How to import Excel file into mysql database using phpmyadmin

无人久伴 提交于 2019-12-19 11:30:06

问题


I want to import from excel sheet format (.xls) to mysql database through phpmyadmin importing option. I understand that we need to convert the format to csv format first before we can import to the phpmyadmin. But unfortunately if I change to csv some special character or symbol will become question mark (?) or other different character/symbol. Please advise me on this as I am really new to phpmyadmin.

Thanks


回答1:


I have answered similary question here https://stackoverflow.com/a/16330428/1570901

If you are familiar with html and php, by using this simply library simplex excel library and script you can create your own excel import to mysql. IT may take few minutes to create but once your create you can use it for life time.

// CREATE A HTML FORM TO UPLOAD EXCEL SHEET

// THEN CREATE A PHP SCRIPT LIKE BELOW

require 'simplexlsx.class.php';

if (isset($_FILES['Filedata'])) {

$file = $_FILES['Filedata']['tmp_name']; // UPLOADED EXCEL FILE

$xlsx = new SimpleXLSX($file);

list($cols, $rows) = $xlsx->dimension();

foreach( $xlsx->rows() as $k => $r) { // LOOP THROUGH EXCEL WORKSHEET

$q = "INSERT INTO TABLENAME(COL1, COL2) VALUE(";
  $q .=  "'".mysql_escape_string($r[0])."', "; // EXCEL DATA
  $q .=  "'".mysql_escape_string($r[1])."', "; // EXCEL DATA
  $q .= ")";

  $sql = mysql_query($q);

    } // IF ENDS HERE
    } // FOR EACH LOOP
}


来源:https://stackoverflow.com/questions/16330242/how-to-import-excel-file-into-mysql-database-using-phpmyadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!