Jargon Guide
Jargon is a set of convenience tools built on top of Creole. Jargon provides some shortcut methods for reading / writing database data. Jargon is completely RDBMS agnostic, relying on Creole to handle vendor differences. Some of the Jargon tools are based on the Village layer for JDBC.
Query
The Query class and PagedQuery subclass provide some PEAR::DB/MDB-like methods for getting database results and ADOdb-like paged query support. These classes are only for retrieving results (executeQuery()).
<?php $q = new Query($conn, "select * from book inner join author on author.id = book.author_id"); $q->getRows(); // returns array of rows (hash), frees result set $q->getRow(); // returns first row (hash) and discards the rest $q->getOne(); // returns first col of first row and discards the rest $q->getCol(); // returns array containing values of first column $q->getAssoc(); // returns array where key is first column and values are all other columns
PagedQuery?
The PagedQuery? class makes it simple to perform paginated database queries. Besides simply setting LIMIT and OFFSET based on page number and rows-per-page value, PagedQuery? also provides the ability to fetch the total number of rows (w/o LIMIT/OFFSET), which is usually important for building a pagination system.
<?php $pq = new PagedQuery($conn, "select * from author", $page=2, $rows_per_page=25); // or $pq->setPage(2); $pq->setRowsPerPage(25); $q->getTotalRecordCount(); // returns total number of rows, ignoring LIMIT/OFFSET
DataSet?
Based on Village, the QueryDataSet and TableDataSet provide containers for Record objects. You can use KeyDef objects with TableDataSet to manipulate Records. E.g.
<?php $tds = new TableDataSet($conn, "author", new KeyDef('id')); $tds->fetchRecords(); foreach($tds as $rec) { // implements SPL Iterator $rec->setValue("name", "me!"); $rec->save(); // UPDATE author SET name = 'me!' WHERE id = ? }
This provides a lighter way to get a little bit of that Propel functionality.
QueryDataSet also uses Record objects, but you cannot save or delete these Records. Because we do not (and cannot) have ResultSetMetadata in Creole, no type conversions are performed when fetching db values in Record objects.
We do, however, have TableInfo classes, so the correct PreparedStatement setter method (e.g. setInt(), setString()) is used when setting values of a TableDataSet Record . Even though it would be possible to have TableDataSet Records also perform correct type conversions when getting values from the resultset, this would introduce inconsistency since Records of QueryDataSet could not do this.
