Very simple database toolkit for PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

PHP Database

Very simple database toolkit for PHP, providing simple pdo wrapper connection and query builder. It currently supports MySQL. Сreated for the study. But you can use it in real projects. Сode taken from Laravel Database Layer and simplified.


First, create a new manager instance.

use Database\Manager;

$manager = new Manager;

    'dsn' => 'mysql:dbname=testdb;host=',
    'username' => 'root',
    'password' => null,
    'options' => [] // pdo driver options 

Once the Manager instance has been registered. You may use it like so:

Using Connection

$conn = $manager->getConnection();
$data = $conn->queryAll('select * from users where id in (?,?,?)', 1, 2, 3);
// $data -> [['id' => 1, 'name' => 'joe'], ...]

$conn->exec('insert into users (id, name) values (?, ?)', 1, 'joe'));


Using The Query Builder

$data = $manager
            ->whereIn('id', [1,2,3])

// $data -> [['id' => 1, 'name' => 'joe'], ...]

$data = $manager
            ->update(['votes' => 2])
            ->where('id', 1)
// $data -> ['update `user` set `votes` = ? where `id` = ?',[2,1]]
$data = $manager
              ['email' => '', 'votes' => 0],
              ['email' => '', 'votes' => 1]

More about query builder see in QueryBuilderTest


The recommended way to install php-database is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:

    "require": {
        "itlessons/php-database": "*"

Alternatively, you can download the file and extract it.


You can run the unit tests with the following command:

$ cd path/to/php-database/
$ composer.phar install
$ phpunit