[eluser]WanWizard[/eluser]
I wasn't talking about the goal.
I just mean that
Code:
$data = mysql_query($sql);
while ($row = mysql_fetch_object($data, "UserVO"))
{
$result[$i] = new UserVO();
$result[$i]->id = $row['id'];
$result[$i]->email = $row['email'];
$i++;
}
return $result;
gives the same result as
Code:
$query = $this->db->query($sql);
return $query->result()
Which is an array of objects, one per row in the resultset.
There is only a difference if UserVO contains methods(). In that case you don't have to do a "new UserVO()", as mysql_fetch_object() will make sure $row already contains an instantiated UserVO object.
I would still opt not to use direct mysql functions, but do
Code:
$query = $this->db->query($sql);
$result = array();
foreach ( $query->result() as $row )
{
$result[] = new UserVO($row);
}
return $result;
and make sure the constructor of your UserVO class picks up the parameter, and assigns it's values to the correct properties.