I want to get the SELECT block of an SQL query, and what I'm thinking is getting the text between the words SELECT and FROM. What is the REGEX I'm supposed to use?
Is it possible to extract the FROM, WHERE and JOIN blocks in the same manner?
UPDATE
I cannot use the http://code.google.com/p/php-sql-parser/ because it is built for MySQL and my MSSQL queries break it. I've searched a lot for an MSSQL parser and couldn't find a ready made solution so the only way I can think of is the parse the SQL myself using regex and work on the principle that the select block is between a SELECT and FROM keyword.
EXAMPLE
For the query
SELECT STRAIGHT_JOIN a,b,c
FROM some_table an_alias
WHERE d > 5;
I want something like this to be returned:
$result['SELECT'] => 'STRAIGHT_JOIN a,b,c';
$result['FROM'] => 'some_table an_alias';
$result['WHERE'] => 'd>5';