2017 © Pedro Peláez
 

library sqlbuilder

Fast and Powerful SQLBuilder for PHP

image

corneltek/sqlbuilder

Fast and Powerful SQLBuilder for PHP

  • Saturday, July 28, 2018
  • by c9s
  • Repository
  • 10 Watchers
  • 108 Stars
  • 8,200 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 15 Forks
  • 28 Open issues
  • 53 Versions
  • 0 % Grown

The README.md

SQLBuilder for PHP

Build Status Coverage Status Latest Stable Version Total Downloads Monthly Downloads Latest Unstable Version License, (*1)

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

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

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., (*4)

Features

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

Synopsis

Here is a short example of using Universal SelectQuery, (*5)

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 = u.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:, (*6)

  1. Question mark parameter marker (?)
  2. Named parameter. (:id, :name, :address, :p1)

The above two are supported by PDO directly, and the first one is also supported by mysqli, pgsql extension., (*7)

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., (*8)

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., (*9)

Universql Queries:, (*10)

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

To see the implementation details, you can check the source code inside Universal namespace: https://github.com/c9s/SQLBuilder/tree/master/SQLBuilder/Universal/Query, (*11)

MySQL Queries:, (*12)

  • CreateUserQuery
  • DropUserQuery
  • GrantQuery
  • SetPasswordQuery

For MySQL platform, the implementation is according to the specification of MySQL 5.6., (*13)

For PostgreSQL platform, the implementation is according to the specification of PostgreSQL 9.2., (*14)

Installation

Install through Composer

composer require corneltek/sqlbuilder

Getting Started

Documentation, (*15)

Development

composer install

Copy the phpunit.xml file for your local configuration:, (*16)

phpunit -c your-phpunit.xml tests

Contribution

To test with mysql database:, (*17)

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

--- or use this to remove password for testing account
SET PASSWORD FOR testing@localhost=PASSWORD('');

To test with pgsql database:, (*18)

sudo -u postgres createdb sqlbuilder

Reference

  • http://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html
  • http://www.postgresql.org/docs/8.2/static/sql-syntax.html
  • http://www.sqlite.org/optoverview.html

Author

Yo-An Lin (c9s) cornelius.howl@gmail.com, (*19)

The Versions

28/07 2018

dev-master

9999999-dev

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

10/05 2017

4.0.0

4.0.0.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

19/06 2016

3.2.x-dev

3.2.9999999.9999999-dev

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

19/06 2016

3.2.4

3.2.4.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

19/06 2016

3.2.3

3.2.3.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

19/06 2016

3.2.2

3.2.2.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

16/06 2016

3.2.1

3.2.1.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

14/06 2016

3.2.0

3.2.0.0

Fast and Powerful SQLBuilder for PHP

  Sources   Download

MIT

The Development Requires

by Avatar c9s

13/06 2016

3.1.0

3.1.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

10/06 2016

3.0.1

3.0.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

10/06 2016

3.0.0

3.0.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

30/12 2015

2.8.9

2.8.9.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

30/12 2015

2.8.8

2.8.8.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

21/11 2015

2.8.6

2.8.6.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

17/10 2015

2.8.5

2.8.5.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

08/10 2015

2.8.4

2.8.4.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

29/09 2015

2.8.3

2.8.3.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

25/09 2015

2.6.x-dev

2.6.9999999.9999999-dev

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

25/09 2015

2.6.3

2.6.3.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

25/09 2015

2.8.2

2.8.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

23/09 2015

2.8.1

2.8.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

22/09 2015

2.8.0

2.8.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

02/08 2015

2.7.2

2.7.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

30/07 2015

2.7.1

2.7.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

30/07 2015

2.7.0

2.7.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

17/04 2015

2.6.2

2.6.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

17/04 2015

2.6.1

2.6.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

17/04 2015

2.6.0

2.6.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

16/04 2015

2.5.0

2.5.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

15/04 2015

2.4.2

2.4.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

15/04 2015

2.4.1

2.4.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

14/04 2015

2.4.0

2.4.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

11/04 2015

2.3.3

2.3.3.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

28/03 2015

2.3.2

2.3.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

11/02 2015

2.0.x-dev

2.0.9999999.9999999-dev

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

11/02 2015

2.3.1

2.3.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

07/02 2015

2.3.0

2.3.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

15/01 2015

2.2.0

2.2.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

11/01 2015

2.1.0

2.1.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

07/01 2015

2.0.0

2.0.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

05/01 2015

2.0-beta

2.0.0.0-beta

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

MIT

The Development Requires

by Avatar c9s

15/10 2014

1.5.x-dev

1.5.9999999.9999999-dev

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

15/10 2014

1.5.7

1.5.7.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

08/08 2013

1.5.6

1.5.6.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

05/07 2013

1.5.5

1.5.5.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

12/05 2013

1.5.4

1.5.4.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

04/05 2013

1.5.3

1.5.3.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

04/05 2013

1.5.2

1.5.2.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

04/05 2013

1.5.1

1.5.1.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

04/05 2013

1.5.0

1.5.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

04/05 2013

1.4.0

1.4.0.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

26/03 2013

1.3.13

1.3.13.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

The Development Requires

by Avatar c9s

24/03 2013

1.3.12

1.3.12.0

Fast and Powerful SQLBuilder for PHP5.3

  Sources   Download

by Avatar c9s