What are the advantages of PDO::FETCH_OBJ?

Asked

Viewed 899 times

1

What are the advantages of using PDO::FETCH_OBJ? I know it returns me an object instead of an array, but what are the advantages of code performance?

  • To answer for sure, s[o with a benchmark. But objects are more effective than arrays, this is fact.

  • Cara can’t tell you precisely which is the most efficient. But I don’t believe the difference in their performance is that significant. The difference is more in the design pattern you will adopt.

  • 1

    You may have mistaken FETCH_OBJ for FETCH_CLASS. FETCH_CLASS does have something to do with Design Patterns because it allows you to send data directly to a Row/Rowset class part of a DAO/Activerecord

  • 3

    Probably there is no real performance advantage over your application, using objects instead of arrays is more for design aesthetics.

1 answer

2


ASSOC, BOTH and OBJ result in the same internal code call, so the difference can only be found in what is returned.

The simplest answer will be to indicate that "There is no difference in performance", however I do not consider it so.

First and most important the number of fields, certain that it is kept in mind that one should only return what is absolutely necessary. That said and for the same amount of information...

The PDO::FETCH_LAZY that is associated with this mechanism forces the creation of objects and their properties according to the need of access to them and then we can evaluate real losses of performance. This means that we can only talk about performance when actually accessing properties and not when performing a fetch().

I would say... if the return has a "huge" amount of fields it will be preferable to force ASSOC, however and for a small number of fields the difference will be derisory that does not represent something worthy of attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.