For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > May 2007 > PDOStatement and fetchAll()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PDOStatement and fetchAll()
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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com