dongpo1846 2012-06-04 08:40
浏览 20
已采纳

解析包含分号的SQL(在PHP中)

I coded a SQL parser that load data from a MySQL dump. The problem is that some SQL statements contain semicolon themselves so my parser take it as EOL as I use

$sqlRows = explode(';', $sqlFile);

to parse the dump file.

Any suggestion on how to manage this? I'm stuck :S

edit:

Sorry I forgot to say that the problem is that when PHP writes data to DB from the dump file, it returns me an error when it read the sentence that contain the semicolon.

I know it's not a full parser, it just read line by line. I'm new to this. I just need to "clone" the same DB (via dump file) to many, changing few data.

  • 写回答

1条回答 默认 最新

  • dongmangji0950 2012-06-04 08:46
    关注

    try this

    $sqlRows=explode(";
    ",$sqlFile);
    

    So you will only get the ; that are at the end of lines. However it'll only work if your file is formatted with each statement finishing by a ; and each new statement beginning on a new line.

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

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制