tags:

views:

103

answers:

1

Which is the better alternative? I've noticed PDO let's you return as an array or an object. I've always used arrays when using my old functions (mysql_fetch_assoc()) but I've just written a wrapper class for the PDO object and I was curious as to which is better.

I suppose an object would be stricter... you can change/add to a returned array which may muddle up your results unexpectedly (if you forgot you added/changed a key/value).

Are returned records in arrays more an old fashioned way, and should I adopt the objects, for which reasons?

+3  A: 

From php.net:

mysql_fetch_object() is similar to mysql_fetch_array(), with one difference — an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

Note on Performance: Speed-wise, the function is identical to mysql_fetch_array(), and almost as quick as mysql_fetch_row() (the difference is insignificant).

Nerdling
Indeed! And this point onwards, its really up to the programmer's taste. Although I personally prefer to arrays.
Swanand