Reputation: 1222
EDIT: Found this which works quite well for what I need: https://github.com/jstayton/QueryBuilder
I'm building a small project where I need to query a table a couple of times.
It works like this:
1) Multi-select box of distinct items in Column 1
2) Ajax query the db for distinct records in Column 2 where Column 1 IN (vals
previously selected)
3) Does this 3-4 more times, gradually cutting down the available options by
adding IN statements to the MySQL
Now it's not impossible to this manually by setting up a couple pre-built queries and binding the various params to them, but I'd like to make it a bit nicer than that. Something along the lines of....
$qry->from("mytable");
$qry->column("col1");
$qry->column("col2");
$qry->addWhere("col1", "in", $arrayOfVals);
$qry->addWhere("col2", "in", $arrayOfVals2);
Or something to that effect, that will build it out in a cleaner way.
Alternatively, if someone has a suggestion on a different way to do this, I'm open to that too.
Upvotes: 1
Views: 2226
Reputation: 2015
I noticed the link you provided in your edit no longer works so for that reason, I'd recommend looking at FluentPDO aswell - http://fluentpdo.com/index.html
It has a very simple installation process and very fluid and natural query building methods which would allow for syntax similar to what you mentioned in your original question.
Upvotes: 0
Reputation: 2870
Zend_Db_Select
has almost the exact syntax you provided. But you'd have to include quite a lot of Zend_Db_* classes for that, I don't know if it's acceptable for you.
http://framework.zend.com/manual/en/zend.db.html
Upvotes: 1
Reputation: 4308
There are an infinite number ways to do this - it all depends on your needs. You could roll your own for sure or go for something already out in the wild.
Take a look at ezSQL http://justinvincent.com/ezsql it may be right up your alley.
Upvotes: 1