douchun5969 2013-03-21 06:02
浏览 163
已采纳

逗号在地址时将CSV文件导入MySQL的问题

I'm using a script that I found online to import CSV file into MySQL: http://www.johnboy.com/blog/tutorial-import-a-csv-file-using-php-and-mysql but when the script detects a comma in an address like this My address, CO 80113 in a cell, it also splits there as well.

I've seen a solution where you can save from excel to a Tab Delimited txt file. Then you go into notepad and replace the tabs with semicolons.

Is this the best practice for "fixing the comma in the address" issue?

My end goal is to take a CSV file from Highrise full of hundreds of clients into our MySQL database, then make updates every couple of months so this seems to be a decent script but am I going at this the wrong way?

EDIT : It appears that the part of the PHP code that splits up the cells is this

while ($data = fgetcsv($handle,1000,",","'")); 
  • 写回答

2条回答 默认 最新

  • duanmi4379 2013-03-21 07:16
    关注

    If you use comma as column separator, then you should quote all string field values, e.g. -

    1,'My address, CO 80113'
    2,'His address, CO 80114'
    4,'Her address, CO 80115'
    and so on
    

    Try to use LOAD DATA INFILE statement with FIELDS ENCLOSED BY '\'' option.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!