In this example, we have a function that calculates the SHA256 sum of a
string, and then reverses it. When the SQL statement executes, it
returns the value of the filename transformed by our function.
The data returned in $rows contains the processed result.
The beauty of this technique is that there is no need to process the
result using a foreach
loop after the query.
<?php
function sha256_and_reverse($string)
{
return strrev(hash('sha256', $string));
}
$db = new Pdo\Sqlite('sqlite::sqlitedb');
$db->sqliteCreateFunction('sha256rev', 'sha256_and_reverse', 1);
$rows = $db->query('SELECT sha256rev(filename) FROM files')->fetchAll();
?>