Help with PHP DataObjects tutorial
Posted: Mon Mar 26, 2007 9:49 am
Hi, don't know if this is the right place to post this or not. I can't seem to post a reply to the tutorial section.
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?
What if, say for instance, I set the name and email of the user in the User object and then want to find if that user exists in the database to see if that name and email are available (this would be for something like registration). If I use getRow() and that user doesn't exist, it will clear all the data I entered. Is this the correct way of using getRow()?
Thanks,
Nathan.
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.