akphidelt2007 Posted October 19, 2012 Share Posted October 19, 2012 (edited) Hi there, so I'm working on a way to be able to write queries and be able to break them down in to their components. For the project I was working on I needed to do a lot of automatic filtering with dynamic WHERE IN statements and other clauses. So I built a query class that could handle that and wrote my queries using that class. But now I'm trying to go the opposite direct and be able to write the query out and have the script deconstruct it and then construct it back together with the added logic I have going on. I'm having trouble finding any scripts on Google, most deal with the URL Query String. But if anyone has done this before and has an example or knows a script out there that would be a good starting point, please let me know. I have a feeling this will involve a lot of regex. If I can't find anything, I will work on developing it myself but just thought it would be nice to have an example to look through. Any help is appreciated, thank you! Just for example purposes. Something like this $qry = " SELECT t1.employee,sum(t1.hours) as Hours,t2.labor_classifiation FROM labor_data t1 LEFT JOIN craft_strings t2 ON t2.id = t1.craft_id "; //This would be broken down in to Array('tables'=>Array( 'labor_data'=>Array( 'fields'=>Array('employee','hours'=>Array('name'=>'Hours','equation'=>'sum')) ,'prefix'=>'t1') )) //that's not the entire array that would come out of it, but you get the picture. Edited October 19, 2012 by akphidelt2007 Quote Link to comment https://forums.phpfreaks.com/topic/269691-breaking-apart-a-query-string-in-to-fieldstables/ Share on other sites More sharing options...
requinix Posted October 19, 2012 Share Posted October 19, 2012 Are you absolutely sure you want to do this? Unless you can find something out there already this will take quite some time to get it right. More time if you want to be able to handle lots of different queries. I doubt this work is really necessary. Deconstruct the manual queries you have by yourself. It may sound like a lot of work but it'll be faster and easier than making this SQL parser thing. Quote Link to comment https://forums.phpfreaks.com/topic/269691-breaking-apart-a-query-string-in-to-fieldstables/#findComment-1386402 Share on other sites More sharing options...
akphidelt2007 Posted October 19, 2012 Author Share Posted October 19, 2012 Of course the work can be done with out it. I just thought it would be a neat idea and make some things I do much more efficient. What I'm trying to do is set up a report builder where I can just type up the query and have it break it down to automatically create it's headers, filtering, authentication, classes, ajax, etc. But I guess you are probably right, it would probably end up being easier just to build the tools to be able to construct the query from the inputs rather than just typing the entire query out and regexing the heck out of it. Alright, I'll try this other method first. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/269691-breaking-apart-a-query-string-in-to-fieldstables/#findComment-1386422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.