Features


Powerful
Simple but powerful syntax, allow complex query execution in single line of code.
Learn more...
Secure
Avoid most SQL query synthax errors and prevent from SQL injection using prepared statement.
Learn more...
Documented
Full online documentation with examples available.
See doc
Open source
Patabase is released under the
MIT License. Learn more...

Powerful




Patabase is a minimalist SQL query builder for PHP. No reinvented wheel, Patabase is build on top of PHP PDO. It provides class and methods to perform queries on a datasource.

Why using it?

Patabase could help to:

Patabase supports the following SQL:

Database queries:
- SELECT FROM:   
    DISTINCT, all / column(s), columns(s)/alias, function(COUNT, SUM), sub select, 
    JOIN        (INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN (*), FULL OUTER JOIN (*))
    WHERE       (=, !=, <, <=, >, >=, IN, NOT IN, NULL, NOT NULL), 
    GROUP BY, 
    HAVING      (COUNT, SUM), 
    ORDER BY    (ASC, DESC, RAND (*)), 
    LIMIT, 
    OFFSET
- INSERT INTO 
- DELETE FROM
    WHERE       (=, !=, <, <=, >, >=, IN, NOT IN, NULL, NOT NULL), 
- UPDATE 
    WHERE       (=, !=, <, <=, >, >=, IN, NOT IN, NULL, NOT NULL), 
- CREATE TABLE (DEFAULT, PRIMARY KEYS, FOREIGN KEYS, NULL/NOT NULL)
- RENAME TABLE
- TABLE EXISTS
- SHOW TABLES
- DROP TABLE
- ENABLE FOREIGN KEY (*)
- DISABLE FOREIGN KEY (*)
- ADD FOREIGN KEY (*)
- DROP FOREIGN KEY (*)

Server queries (*):
- CREATE DATABASE
- CREATE USER
- USER EXISTS
- DATABASE EXISTS
- SHOW USERS 
- SWOW DATABASES
- GRANT USER
- DROP DATABASE
- DROP USER

Suppose a table named 'user' in a sqlite database locate in '/home/mydatabase.db' with the following data:

|------|-------|-------|
|  id  | name  |  age  |
|------|-------|-------|
|   1  | Bryan |   34  |
|   2  | Steve |   32  |
|   3  | John  |   18  |
|   4  | Chris |   38  |
|   5  | Jane  |   16  |
|   6  | Bryan |   27  |
|------|-------|-------|

You want to find the name of user with id of 2. You could write:

echo new Kristuff\Patabase\Database(array('driver' => 'sqlite', 'database'  => '/home/mydatabase.db'))
            ->select('name')
            ->from('user')
            ->whereEqual('id', 2)
            ->getColumn();

...and get the following result:

Steve

You want to if and name of user respecting the following conditions (age < 17 OR age > 37) AND (id > 4), in JSON format. You could write:

echo new Kristuff\Patabase\Database(array('driver' => 'sqlite', 'database'  => '/home/mydatabase.db'))
                ->select('id', 'name')
                ->from('user')
                ->where()
                    ->beginOr()
                        ->lower('age', 17)
                        ->greater('age', 37)
                    ->closeOr()
                ->where()->greater('id', 4)
                ->getAll('json');

...and get the following result:

[{"id":5,"name":"Jane"}]

Magic!

Secure




No SQL synthax errors

Avoid most SQL synthax query errors, common or driver related.


No SQL injection

Avoid SQL injection using parametized queries.


No type mismatch

Avoid SQL types errros with appropriate binding parameters values.


Solid base

Build on top of PDO.


Open source



Patabase source code is released under the MIT License


Learn more...