Anyway, I stumbled across Maugrim_the_Reaper's tutorial PHP DataObjects: Simplifying Business Logic without SQL and really liked it.
I just have a question, maybe more later, on one function in the DataAccess class - getRow(). I understand how it works, but I'm just wondering what's the reason for clearing all the data values in the DataObject class if no records are found?
Code: Select all
<?php
// ...
function getRow(&$do) {
$conditions = $this->getSetFields($do);
$sql = 'SELECT * FROM ' . $do->getTableName() . ' WHERE ' . implode(' AND ', $conditions['fields']);
$result = $this->db->SelectLimit($sql, 1, -1, $conditions['values']);
if(!$result)
{
trigger_error($sql . '<br /><br />' . get_class($this) . ': ' . $this->db->ErrorMsg(), E_USER_ERROR);
}
if(!empty( $result->fields ))
{
$do->import( $result->fields );
$do->setExists();
}
else
{
$do->clearData();
}
$result->Close();
}
// ...
?>Thanks,
Nathan.