As an excersise I have started building another php based sql query builder (separate from my stagnating php framework). So far I can do SELECT [columns] FROM table WHERE [conditions]
This is how it should be used (so far):
(for the examples, assume that $q is a query object)
$q->table('test')
->column('test_2', 'test')
->table('test_3', 'test_2');
//=> SELECT test_2 as test FROM test, test_3 AS test_2
You can also group conditions:
$q->table('table')
->begin_and()
->and_where('col_1', 1)
->or_where('col_2', 2)
->end_and()
->or_where('col_3', 3, '!=');
//=>SELECT * FROM table WHERE ( col_1 = '1' OR col_2 = '2' ) or col_3 != '3'
which is fun.
I have just tried this example and am pleased to say that you can put multiple groups at the start of the query:
$q->table('table')
->begin_and()
->begin_and()
->and_where('col_1', 1)
->or_where('col_2', 2)
->end_and()
->end_and()
->or_where('col_3', 3, '!=');
//=>SELECT * FROM table WHERE ( ( col_1 = '1' OR col_2 = '2' ) ) OR col_3 != '3'
You can follow along here if you want, suggest improvements, criticize it to no end because I am doing it toally wrong, or “steal” my ideas and make your own (but give me some of the credit at least).