Database return records as object or array?

Tags: php mysql pdo
By : alex

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?

By : alex



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

By : Nerdling

I always recommended DevArt db components fro their performance and reliability.

You can choose between SDAC(for direct access to sql server) or UniDac (direct access to Sql server, Oracle, MySql,PostgreSql and Interbase/firebird)

if you don't require the advanced components that access specific features of sql server like TMSChangeNotification, TMSTransaction or TMSServiceBroker, then you can go with UniDac so your application will be designed to work with multiple databases.

The AnyDAC offers great feature set and performance, as simplifies development of the database applications. AnyDAC supports MS SQL Server, MS Access and much more.

By : da-soft

This video can help you solving your question :)
By: admin