A simple API for Database Access
- Simple API
- prevent SQL injection with automatic whitelist column filter and pdo prepared statements
$ composer require dboho/simple-database-api
# select
$result = $da->select('books', ['title'], ['author'=>'Rasmus Lerdorf']);
echo(json_encode($result));
# insert
$da->insert('books', ['title'=>'Using the New DB2', 'author'=>'Don Chamberlin']);
# update
$da->update('books', ['price'=>9.80], ['id'=>1023]);
# delete
$da->delete('books', ['id'=>1021]);
To prevent SQL injection all attributes that are used as column names will be filtered with a whitelist. This whitelist is build for each queried database table.
Books Table
id | title | author | price |
---|---|---|---|
1 | Programming PHP | Rasmus Lerdorf | 39.99 |
Whitelist for the books table will contain id, title, author and price.