1.2 KiB
1.2 KiB
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');