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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题