DB_Table: Pre-Defined Per-Query Fetchmodes
Ian Eure just provided a patch to DB_Table that is genius in its simplicity. While I have not tested it, the patch looks like it will cause no trouble. In short, in your predefined SQL queries, you can specify that the query should return in DB_FETCHMODE_ASSOC, DB_FETCHMODE_ORDERED, or any other fetchmode. For example:
// predefined query for a list of all rows $this->sql['list'] = array( 'select' => '*', 'from' => $this->table, 'order' => 'some_column DESC', 'get' => 'all', 'fetchmode' => DB_FETCHMODE_ASSOC ); // predefined query for a single row $this->sql['item'] = array( 'select' => '*', 'from' => $this->table, 'get' => 'row', 'fetchmode' => DB_FETCHMODE_OBJECT, 'fetchmode_object_class' => 'myDataObjectClass' );
With that, you can call
$dbTable->select('list') and get an array of rows, or call
$dbTable->select('item', "id = '9'") and get an object of type
This is only in CVS right now, as I'm trying to add various Oracle restrictions to DB_Table, but it was just too neat to not add in right away. Thanks, Ian Eure.
DB_Table is a PHP class to automatically create RDBMS tables and XHTML forms. It includes a "poor man's" data type abstraction wherein the database is forced to store date and time data in ISO formats, which means you do not need to do date/time magic on your queries before executing them (and you don't need to do magic on the return results, either).