doulu4976 2014-03-18 05:35
浏览 30
已采纳

.csv文件进入mysql

The server I'm using does not allow me to use LOAD DATA INFILE or even save a file as a .txt file. I have a .csv file that is just one column, with a name in each row. I want to insert this data into the name column of a table named people with name as one column and location as the other… where the locations will be updated at a later time.

It's a weird way to do this. But I need to do it this way and not using those previous commands.

Does anybody have any ideas? This has been giving me a problem for many hours. I can't figure out how to load the csv into my table column without using those previously mentioned methods that I can't use on my server.

  • 写回答

1条回答 默认 最新

  • doucigua0278 2014-03-18 06:06
    关注

    Based on your issue and lack of general permissions you will have to do the following:

    Replace the DOS carriage returns with unix new lines:

    $contents=preg_replace('/(
    ||
    )/s',"
    ",$contents); 
    

    Save the contents to the file, and then loop through each line, building an INSERT command that you execute to MySQL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路