ADOdb Library for PHP Manual
Prev Recordset Filters
Next

Recordset Filters

Sometimes we want to pre-process all rows in a recordset before we use it. For example, we want to ucwords all text in recordset.

    include_once('adodb/rsfilter.inc.php');
    include_once(
'adodb/adodb.inc.php');

    
// ucwords() every element in the recordset
    
function do_ucwords(&$arr,$rs)
    {
        foreach(
$arr as $k => $v) {
            
$arr[$k] = ucwords($v);
        }
    }

    
$db = NewADOConnection('mysql');
    
$db->PConnect('server','user','pwd','db');

    
$rs = $db->Execute('select ... from table');
    
$rs = RSFilter($rs,'do_ucwords');

The RSFilter function takes 2 parameters, the recordset, and the name of the filter function. It returns the processed recordset scrolled to the first record. The filter function takes two parameters, the current row as an array, and the recordset object. For future compatibility, you should not use the original recordset object.


Prev Home Next
Exporting in CSV or Tab-Delimited Format Up Smart Transactions

Sponsored by phpLens