Database MySQL PHP
Need help with SQLBuilder?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.


A powerful, fast, cross-platform SQL Builder for PHP. Convert your structured data into SQL queries with a fluent style interface and targeting on all the mainstream database (MySQL, PostgreSQL, SQLite)

130 Stars 18 Forks Other 1.0K Commits 26 Opened issues

Services available

Need anything else?

SQLBuilder for PHP

Build Status Coverage Status Latest Stable Version Total Downloads Monthly Downloads Latest Unstable Version License

If you're looking for something that is not an ORM but can generate SQL for you, you just found the right one.

SQLBuilder is not an ORM (Object relational mapping) system, but a toolset that helps you generate cross-platform SQL queries in PHP.

SQLBuilder is a stand-alone library, you can simply install it through composer or just require them (the class files) with your autoloader, and it has no dependencies.


  • Simple API, easy to remember.
  • Fast & Powerful.
  • Custom parameter marker support:
    • Question-mark parameter marker.
    • Named parameter marker.
  • Configurable quote handler.
  • Zero dependency.


Here is a short example of using Universal SelectQuery

use SQLBuilder\ArgumentArray;
use SQLBuilder\Universal\Query\SelectQuery;
use SQLBuilder\Driver\MySQLDriver;
use SQLBuilder\Driver\PgSQLDriver;
use SQLBuilder\Driver\SQLiteDriver;

$mysql = new MySQLDriver; $args = new ArgumentArray;

$query = new SelectQuery; $query->select(array('id', 'name', 'phone', 'address','confirmed')) ->from('users', 'u') ->partitions('u1', 'u2', 'u3') ->where() ->is('confirmed', true) ->in('id', [1,2,3]) ; $query ->join('posts') ->as('p') ->on('p.user_id =') ; $query ->orderBy('rand()') ->orderBy('id', 'DESC') ;

$sql = $query->toSql($mysql, $args);

var_dump($sql); var_dump($args);

A More Detailed Description

Unlike other SQL utilities, SQLBuilder let you define the quote style and the parameter marker type. there are 2 parameter marker type you can choose:

  1. Question mark parameter marker (
  2. Named parameter. (

The above two are supported by PDO directly, and the first one is also supported by


The API is dead simple, easy to remember, you can just define one query, then pass different query driver to the query object to get a different SQL string for your targettting platform.

It also supports cross-platform query generation, there are three types of query (currently): Universal, MySQL, PgSQL. The Universal queries are cross-platform, you can use them to create a cross-platform PHP API of your database system, and the supported platforms are: MySQL, PgSQL and SQLite.

Universql Queries:

  • CreateDatabaseQuery
  • DropDatabaseQuery
  • SelectQuery
  • InsertQuery
  • UpdateQuery
  • DeleteQuery
  • UnionQuery
  • CreateIndexQuery
  • DropIndexQuery

To see the implementation details, you can check the source code inside Universal namespace:

MySQL Queries:

  • CreateUserQuery
  • DropUserQuery
  • GrantQuery
  • SetPasswordQuery

For MySQL platform, the implementation is according to the specification of MySQL 5.6.

For PostgreSQL platform, the implementation is according to the specification of PostgreSQL 9.2.


Install through Composer

composer require corneltek/sqlbuilder

Getting Started



composer install

Copy the

file for your local configuration:
phpunit -c your-phpunit.xml tests


To test with mysql database:

mysql -uroot -p
GRANT ALL PRIVILEGES ON sqlbuilder.* TO 'testing'@'localhost' identified by '';

--- or use this to remove password for testing account SET PASSWORD FOR [email protected]=PASSWORD('');

To test with pgsql database:

sudo -u postgres createdb sqlbuilder




Yo-An Lin (c9s) [email protected]

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.