Solved

Analyze SQL Query before Running

Posted on 2006-11-27
3
180 Views
Last Modified: 2011-09-20
Hi,
Is there a way for MySQL to verify that a SQL statement is syntactically and logically correct before running the actual statment? I have a few insert statements that allow form data and I want a way to verify that the SQL is robust and will correctly execute before running the actual query (I'm using PHP also).

--Dan
0
Comment
Question by:dancablam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 18021670
You can put EXPLAIN in front of it (assuming a SELECT statement).  That will highlight systactic errors (but not logic errors - you'd probably need to see the results to verify those).
0
 
LVL 30

Accepted Solution

by:
todd_farmer earned 500 total points
ID: 18021690
An example:

mysql> select * from doesnt_exist;
ERROR 1146 (42S02): Table 'test.doesnt_exist' doesn't exist
mysql> explain select * from doesnt_exist;
ERROR 1146 (42S02): Table 'test.doesnt_exist' doesn't exist

It will catch all SQL syntax errors or invalid table/column errors.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 18023470
If you use MySQL query browser it will colour code the query as you construct it, so keywords turn blue, table names red etc.  So you could tell by looking at the colours of the text to see if your syntax is valid.
0

Featured Post

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question