You all misunderstood my question, please read my replies above... I'm looking to extract it from a string - *I'm not executing the queries, I only get them as a string* And to the topic: Since everything I found was very complicated to parse, I've crafted my own preg pattern, "/^(\*|[a-z_, \(\)0-9]+)[\s]+FROM[\s]+([a-z_\. ]+)\s+(WHERE[\s]+(.+)|)\s*(|ORDER BY ([a-z0-9, ])(|\s(DESC|ASC)))\s*(|LIMIT\s+([0-9]+)\s*,\s*([0-9]+))\s*$/Ui" (Assuming this is a SELECT string, and the subject is something similar to: * FROM table WHERE field2='field3' LIMIT 0,10 (Yes, no SELECT - I've got another function to determine whether its select, insert, update, delete from - etc, and it returns to query without the name of the command - "SELECT field FROM table" => "field FROM table") (Without using joins or things like that) But I don't have much experience crafting patterns like that - or working with them so I'd be glad if you think of a better way of doing it, and.... problem is since I'm using sub-brackets, its hard to process it since if there is WHERE and a LIMIT, then LIMIT (...) will be on $result[$n] (for example), But if there is no WHERE, then LIMIT (...) will be on $result[$n - 2]; How should I overcome this problem? 2009/8/21 Daevid Vincent <daevid@xxxxxxxxxx> > > -----Original Message----- > > From: Nisse Engström [mailto:news.NOSPAM.0ixbtqKe@xxxxxxxx] > > > > If you're using MySQL, you can try mysql_field_name() > > and see if it gets you anywhere. I don't think it works > > on empty results though. > > > FYI. It will. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Use ROT26 for best security