PHP MySQL SQL parser (INSERT and UPDATE)

前端 未结 6 1263
误落风尘
误落风尘 2020-12-03 17:37

I am looking to parse INSERT and UPDATE MySQL SQL queries in PHP to determine what changes where made from what original data. Now this would be pretty easy to create, but I

相关标签:
6条回答
  • 2020-12-03 18:18

    A little bit off the question, but maybe a suggestion worth thinking about:

    Since MySQL 5.0, the support for triggers is quite good. If you want to keep a record of what changes have been made to a database, instead of storing the sql statements, you could also define insert/update triggers and define another table in which these values can be stored. You could, for example create a simple table having the fields

    timestamp, user, field, old_value, new_value
    

    and insert the respective values whenever a DML on one of your watched tables occured. To simplify this even more, you could add the field

    table
    

    to the "tracking table" to store all changes to all watched tables in one place.

    See the MySQL manual for more infos about this topic.

    0 讨论(0)
  • 2020-12-03 18:19

    http://pear.php.net/package/SQL_Parser

    http://sourceforge.net/projects/txtsql

    http://code.google.com/p/php-sql-parser

    For Perl there's more variety

    0 讨论(0)
  • 2020-12-03 18:20

    You may give it a chance: SQL Parse and Compile

    0 讨论(0)
  • 2020-12-03 18:20

    In a nutshell, I found that the PEAR:SQL_Parser package has provided the cleanest short-term solution whilst the PEAR:PHP_Parser_Generator package (the generator that FSQL uses) looks like a really robust longer term solution.

    I found txtSQL wasn't robust enough and didn't parse SQL well enough to warrant using, at least in my opinion.

    0 讨论(0)
  • 2020-12-03 18:31

    you can try : dqml2tree sql(dql and dml) query parser written in php

    0 讨论(0)
  • 2020-12-03 18:41

    Facebook released a open-source PHP version of their FQL parser. From what I was it was quite neat code. You could possibly hack that to work with regular SQL.

    0 讨论(0)
提交回复
热议问题