Welcome Guest, Not a member yet? Register   Sign In
mysql_fetch_object
#4

[eluser]WanWizard[/eluser]
I wasn't talking about the goal. Smile

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.


Messages In This Thread
mysql_fetch_object - by El Forum - 08-18-2010, 04:31 AM
mysql_fetch_object - by El Forum - 08-18-2010, 07:23 AM
mysql_fetch_object - by El Forum - 08-18-2010, 08:25 AM
mysql_fetch_object - by El Forum - 08-18-2010, 10:57 AM
mysql_fetch_object - by El Forum - 08-18-2010, 11:45 AM
mysql_fetch_object - by El Forum - 08-18-2010, 01:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB