dev-unit-tests
dev-unit-testsFlat-file database in PHP.
MIT
The Requires
The Development Requires
by Saul Johnson
Flat-file database in PHP.
Flat-file database in PHP., (*1)
, (*2)
Based on the Fllat and Prequel libraries by Wylst. Special mention for Alfred Xing who seems to be the main contributor behind both. With added support for:, (*3)
Install Condense via Composer like this:, (*4)
composer require lambdacasserole/condense
Or alternatively, if you're using the PHAR (make sure the php.exe
executable is in your PATH):, (*5)
php composer.phar require lambdacasserole/condense
To initialize a new database or load an existing one, do this., (*6)
$db = new Database('employees');
This will, by default, create a file db/employees.dat
or load that file, if it already exists. You can change the path at which the flat file database will be created thusly., (*7)
$db = new Database('employees', '../storage');
The constructor also accepts a third parameter which allows you to specify a key to use to encrypt the database with., (*8)
$db = new Database('secrets', '../private', 'my-secret-password');
When loading the database again, this same password must be used., (*9)
Use insert
to add a record (row) to the database., (*10)
$hire = ['first_name' => 'Ethan', 'last_name' => 'Benson', 'salary' => 20000]; $employees->insert($hire);
Condense provides several methods for data retrieval., (*11)
Use the get
method. Specify a field name, another field name, and a value. It will return the value of the first field where (in the same row), the value of the second field matches the given value., (*12)
// Returns the salary of the first employee with the first name 'Ethan' (20000). $employees->get('salary', 'first_name', 'Ethan');
Use the select
method. Returns some (or all) fields in a table, specified by giving an array of desired field names., (*13)
// Returns the whole database. $employees->select([]); // Returns the first name of each employee, for example: // [['Ethan'],['Thomas'],['James']] $employees->select(['first_name']);
Condense provides a couple of methods for updating existing data in a database., (*14)
Use the to
method to update one field for any row satisfying a condition., (*15)
// Change every employee with a first name 'Ethan' to have the surname 'Smithers'. $employees->to('last_name', 'Smithers', 'first_name', 'Ethan');
Use the update
method to update a row by index., (*16)
// Change the first row in the database completely. $employees->update(0, ['first_name' => 'Alison', 'last_name' => 'Bradberry']);
Use the remove
method to delete a row in the database., (*17)
// Remove the first row in the database. $employees->remove(0);
This is a flat file database system. It removes the headache of setting up and configuring a database server, but introduces a few of its own:, (*18)
Flat-file database in PHP.
MIT