sy / db
Simple database layer on top of PDO
1.3.2
2026-11-29 22:23 UTC
Requires
- php: >=5.6.0
- psr/log: ^1.1
Requires (Dev)
- phpunit/phpunit: ^13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Database layer based on PDO
Installation
Install the latest version with
composer require sy/db
Basic Usage
<?php use Sy\Db\Gate; // connection $this->gate = new Gate('sqlite:' . __DIR__ . '/database.db'); // create table $this->gate->execute(' CREATE TABLE test_table ( id INTEGER PRIMARY KEY, name TEXT NOT NULL ) '); // insert $this->gate->insert('test_table', ['id' => 1, 'name' => 'hello']); // select $res = $this->gate->queryAll('SELECT * FROM test_table', PDO::FETCH_ASSOC); print_r($res);
Output
Array
(
[0] => Array
(
[id] => 1
[name] => hello
)
)
Tests
composer test
The test script enables the coverage driver itself (XDEBUG_MODE=coverage),
so nothing has to be exported first, and --coverage-filter src keeps the report
on this package.
GateTest opens the default connection, sqlite::memory:, so the suite needs the
pdo_sqlite extension: without it PHPUnit reports PDOException: could not find driver on every Gate test (the Sql test still runs) and the script exits
non-zero.