Hi all.
I've been struggling with writing a script to query a mysql table by lots of different criteria - generating SQL like this:
SELECT field1, field2, field3, field4, field5 FROM table1 WHERE field4>6 AND field5='value1' ORDER BY field1 DESC LIMIT 0,10
depending on form input.
Is there a class out there that makes this any easier? At the moment I've got about 200 lines of code that aren't reusable for anything else.
Does anyone think a class would help matters, or would it be pointless?
Yours interestedly,
deafpanda
Building SQL queries - is there an easier way?
Moderator: General Moderators
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Re: Building SQL queries - is there an easier way?
Depends on the specific pain you feel
. Is it building lengthly hard to maintain queries, or just getting the form data into whatever you use to build the query? PHP has lots of both Form managers and also the commonly used Database Abstraction/ORM libraries for both needs.
Re: Building SQL queries - is there an easier way?
Well, my specific pain is that I'm making search forms for several different tables on a database. Users can search by up to five criteria on each table, choose operators (less than, greater than, equal to). Writing all the code for a search form for one table took me quite a while, I'm loathe to write similar code for the others.
I don't imagine database abstraction layers can help me with this?
Thanks for your help!
I don't imagine database abstraction layers can help me with this?
Thanks for your help!