10

I am building application which needs to have OOP style MySQL query builder. I want to be able to flexibly build complex queries using only PHP and to get resulting query string for execution with my own database driver.

Does anyone know of a good standalone query builder for PHP? Please note that I don't need database driver I need bare MySQL query builder class (preferably written with camel style function and variable names).

0

4 Answers 4

6

Finally I took Doctrine ORM

and modified it little bit to build SQL instead of DQL.

This works very nice and it able to construct complex queries.

Edit: You can find my final stable implementation in Stingle framework. Look at Db/QueryBuilder plugin.

Sign up to request clarification or add additional context in comments.

Comments

5

DSQL - Query Builder for PHP is exactly what you're looking for, no dependencies and has MIT license:

$query = new atk4\dsql\Query();
$query  ->table('employees')
    ->where('birth_date','1961-05-02')
    ->field('count(*)')
    ;
echo "Employees born on May 2, 1961: ".$query->getOne();

https://github.com/atk4/dsql

Documentation: http://dsql.readthedocs.io/

Comments

2

The PhpToolCase library has a stand-alone query builder tool that is quite easy and handy to use.

There is full join support aswell: http://phptoolcase.com/guides/ptc-qb-guide.html

And ya, it seems to be written with camel style function and variable names :)

Comments

0

There is one version of query builder there (LGPL licenced). I haven't used it, but you might want to take a look at it, if it suits your purposes: http://code.google.com/p/mysql-query-builder/

2 Comments

This very good one, but it lack ability to make left, inner, outer joins.
How can it be 'very good' yet not support joins? That's pretty much fundamental. It's also untouched for over 3 years, may have uncertain support on newer PHP versions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.