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?

1 Answer 1

3

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).

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.