A simple-to-use PHP SQLite database wrapper built on PDO and its SQLite driver.
Go to file
2024-07-01 13:58:37 -05:00
.gitignore Initial commit 2024-07-01 13:10:10 -05:00
Database.php Remove DBLite branding 2024-07-01 13:58:37 -05:00
LICENSE Initial commit 2024-06-30 20:25:20 -05:00
README.md Remove DBLite branding 2024-07-01 13:58:37 -05:00
test.php Initial commit 2024-07-01 13:10:10 -05:00

Database

This SQLite database wrapper provides a simple-to-use interface using PDO's SQLite driver. It was designed to have method signatures very close to Laravel's Eloquent ORM. There are not, however, any ORM features in this wrapper. These must be handled at the model level.

By default, foreign keys are enabled and the database is in WAL mode. In general these defaults should be perfect for most use cases.

Testing

I wrote a simple test file; run it with PHP directly. php test.php This test script covers almost every relevant method in the class.

Examples

$db = new Database('test.db');

$db->table('test')->create([
    'id INTEGER PRIMARY KEY',
    'name TEXT NOT NULL',
    'age INTEGER DEFAULT 18'
]);

$db->table('test')->insert([
    'name' => 'John',
    'age' => 32
]);

$db->table('test')->where('name', '=', 'John')->select();
$db->table('test')->where('age', '>', 16)->selectAll();

$db->table('test')->where('name', '=', 'John')->delete();

Notes

Database->table() sets the current working table's name; there is no real need to use it for every query.

$db->table('test');
$db->where('name', '=', 'John')->select();
$db->where('age', '>', 16)->selectAll('age');