Extract column names from a (my)SQL query
| From: | דניאל דנון | Date: | Wed, 19 Aug 2009 19:42:36 +0000 |
| Subject: | Extract column names from a (my)SQL query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-296983@lists.php.net to get a copy of this message | ||
Lets assume I have the following string:
"SELECT field1, field2, field3 FROM tablename WHERE field1 = 'something' "
Is there any way to get "field1, field2, field3"? assuming it might also
have join, left join - things like that.
I can easily do it with preg_match, but I have to make sure its "foolproof".
It would be a lot better if it will also be able to parse the whole query -
catch limit, where, joins, comments....
Is there any php class that could do it?
I've looked in the pear site and on Google but haven't had any luck.
--
Use ROT26 for best security