What are the advantages of using PDO :: FETCH_OBJ? I know that I get an object instead of an array, but what are the performance advantages of the code?
What are the advantages of using PDO :: FETCH_OBJ? I know that I get an object instead of an array, but what are the performance advantages of the code?
ASSOC, BOTH, and OBJ result in the same internal code call, so the difference can only be found in what is returned.
The most simplistic answer will be to indicate that "There is no difference in performance", however I, so I do not.
First and foremost the number of fields, certain that it is kept in mind that one should only return what is absolutely necessary. Having said that 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 to access them and then we can evaluate real performance losses. This means that you can only talk about performance when you actually access properties and not when fetching ().
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 ridiculous that does not represent something that is worthy of attention.