Yellow Bird Yellow Bird - 25 days ago 18
MySQL Question

How can I check a MySQL query syntax?

I'm working on my own database management system, developped in PHP, and I've chosen the same syntax as the MySQL queries for my own queries.

I'd like to know if there was a tool to check that a MySQL query is valid, without having to connect to a real MySQL database.

Does someone have a way to do it ? I've though about using some regular expressions but I'm not sure this is the easiest (and fastest) way to do this.

Thank in advance !

Answer

There's a few good PHP SQL parsers that break down the query into structured arrays.

You could run the code through the parser and see if it breaks to determine whether it's valid syntax.

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

and

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

are 2 I have used in the past.

Comments