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

[eluser]JonoB[/eluser]
I usually use a php class to create value objects for my database objects. Something like:

Code:
class UserVO
{
    public $id;
    public $email;
}

and I then return this as follows:
Code:
$data = mysql_query($sql);
while ($row = mysql_fetch_object($data, "UserVO"))
{
    $result[] = $row;
}
return $result;

I'm now trying to get to grips with CI and the ActiveRecord methods.

I realise that I could do something like the following, buts its a bit more clunky, especially with queries that contain a lot of fields.
Code:
foreach ($query->result_array() as $row)
{
    $result[$i] = new UserVO();
    $result[$i]->id = $row['id'];
    $result[$i]->email = $row['email'];
    $i++;
}
return $result;

So, my question: is there a way to get "class_names" (as per http://php.net/manual/en/function.mysql-...object.php) when returning data using the CI ActiveRecord methods?


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