Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL query builder PHP class

Tags:

oop

php

mysql

class

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).

like image 475
Alex Amiryan Avatar asked Apr 02 '12 10:04

Alex Amiryan


2 Answers

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.

like image 106
Alex Amiryan Avatar answered Sep 30 '22 00:09

Alex Amiryan


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/

like image 32
romaninsh Avatar answered Sep 29 '22 22:09

romaninsh