mysql_fetch_object cast as object?
Posted: Tue Feb 28, 2006 9:09 am
So as it seems like their should be an effective way of doing this, my question is as follows.
Inside my class constructor I have AssignVariables() let's say that assigns all the member variables of a given object after the key has been assigned.
My SQL statement will return a single row and assign all of these variables. Using mysql_fetch_object this will look like this:
$this->var1 = $row->var1;
$this->var2 = $row->var2;
$this->var3 = $row->var3;
etc...etc...
It just seems tedious and somewhat unecessary as we're basically just casting the returned object as a custom object, with the same number of variables in a specific order.
So, is this just an accepted problem or is there a commonly used solution to reduce the amount of code reuse?
Inside my class constructor I have AssignVariables() let's say that assigns all the member variables of a given object after the key has been assigned.
My SQL statement will return a single row and assign all of these variables. Using mysql_fetch_object this will look like this:
$this->var1 = $row->var1;
$this->var2 = $row->var2;
$this->var3 = $row->var3;
etc...etc...
It just seems tedious and somewhat unecessary as we're basically just casting the returned object as a custom object, with the same number of variables in a specific order.
So, is this just an accepted problem or is there a commonly used solution to reduce the amount of code reuse?