Skip to content
apply a custom PHP function to a subset of values in a PDO-accessible database
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Simple class to iterate over a database using PDO and modify columns by applying a custom PHP function.

Used to encrypt data managed in a legacy codebase.

It requires tables to have a PK column named "id", change the code if you need to.

Unit tested with PDO mocks, 100% coverage. Build Status

Example of usage

Edit the data of a single user (just capitalise first char of user info and data)

$pdo = new PDO(/*...*/);
$makeUppercase = function ($string) { return ucfirst($string);};

make upper case column first_name and last_name of user with ID 1 and 2

$modifier = new DbModifier($pdo, $makeUppercase);
    'user', // table name
    array(1,2), // IDs of records to modify
    array('first_name', 'last_name') // columns to modify

more advanced example: make upper case user 3 and his posts

userId = 3;
    array('first_name', 'last_name')
    $modifier->getTableIds('SELECT id FROM posts WHERE user_id = ' . $userId), // get user's post IDs 
    array('name', 'description')
You can’t perform that action at this time.