ADODB database abstraction library for PHP

I’ve been using this library for years to make my database interface code database-independent, but I am still discovering new useful functions. Case in point: today I was using the handy rs2csv function, which outputs a recordset to a CSV file with a few lines of code …

$fp = fopen($file, "w");
if ($fp) {
rs2csvfile($rs, $fp);
fclose($fp);
}

But I needed to massage some of the rows in the recordset before writing them to the file. I struggled for a while before finding RSFilter:
$rs2 = RSFilter($rs, 'callbackfunction');

The callback function takes two arguments: the recordset and an array (passed by reference) representing a single row of the recordset (see the example in the link to the documentation above). RSFilter deals with running the function on each row, and returns the duly massaged recordset ready for output to the file.

This entry was posted in Databases, PHP, Web development and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>