Reputation: 8508
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.
Upvotes: 1
Views: 10849
Reputation: 2543
a tool like that can't ensure tables or columns exist. the tool needs database schema for checking errors. I use heidisql and If I had more money ı would buy right to have more than one database on mysql server and I would execute the "create database" or copy database code and test on the second database which doesn't have any values, or prefereably, with values.
Upvotes: 1
Reputation: 21531
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.
Upvotes: 5