程式碼: $db = mysql_connect("ip","account","password"); $db_selected = mysql_select_db("mydb",$db); mysql_query("SET NAMES 'utf8'"); $file = fopen("mycsv.csv","rb"); while(!feof($file)) { $line = fgets($file); $line = iconv("big5","utf-8",$line); $tmp = explode(",",$line); $sql = "INSERT INTO data (data1,data2,data3) VALUES ('$tmp[0]','$tmp[1]','$tmp[2]')"; mysql_query($sql,$db); } mysql_close($db); csv檔由xls檔另存新檔成csv(逗號分隔),即可直接匯入。
沒有留言:
張貼留言