| James McLean 2007-05-03, 6:57 pm |
| Howdy,
I'm working with PDOStatement->fetchAll() and I need it to return the
Object I specify. I've got it working with individual rows and
PDOStatement->fetchObject(), i'm able to tell it what class to load
the variables into with this function and if I read correctly I should
also be able to do this with fetchAll() also.
The http://au.php.net/manual/en/functio...nt-fetchAll.php
page says I should be able to use the $fetch_style outlined on the
fetch() page, but its not very clear hot to specify which class to
load.
For example, this code:
return $queryData->fetchObject(get_class($this));
does exactly what i want it to, puts the variables into the class I
specify so I can handle the data with custom methods..
I need to do the same with a fetchAll. I have it returning with an
anonymous object (called stdClass, the default) but would like to know
how to specify the object to call as above, as I need the flexibility
of custom classes with these result sets also.
I've experimented a little with the fetchAll() method, for example:
return $queryData-> fetchAll(PDO::FETCH_CLASS|PDO::FETCH_CLA
SSTYPE);
and
return $queryData-> fetchAll(PDO::FETCH_CLASS|get_class($thi
s));
but both still only return the stdClass object..
Can someone explain how to do this with fetchAll() a little more clearly?
Cheers,
James
|