Hi,
does anybody here know or has used a regular expression to tokenise a Mysql
query? What I'm looking at is getting the parts of the query in an array of
matches, i.e. the 'select ...' part, the 'from ...' part etc.

I got this one for now, but it has some shortfalls:

$found = preg_match
('/^(\s?(SELECT|select)(.*?)\s(FROM|from)\s([^\s]+)(\s+((AS|as)\s+)?([^\s]+))?(\s+?(JOIN|join|LEFT|left|NATURAL|natural|RIGHT|right|INNER|inner).*?)?)(\s+(WHERE|where)\s(.+?))?(\s+(GROUP
BY|group by)\s.+?)?(\s+(ORDER BY|order
by)\s(.+?))?(\s+(LIMIT|limit)\s.*)?$/sm', $sql, $matches);


- would be great to have all joins in a separate array, this probably needs
to be done in a second step
- doesn't handle table names with spaces, ie. `table name`


Any other issues anyone can see? Any regex or libraries that you've used?

Kind Regards,

Jochen

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to