From an OOP perspective, what is the proper way to create a DAO (Data Access Object) in php?
For example (using Account as a basic example), my AccountDAO will have some of the following functions:
GetAllAccounts
GetAccountByID
UpdateAccount
DeleteAccount
InsertAccount
So once I fetch all of the Accounts in the database, should I return them to the caller as an array of account objects? Should I just return the mysql result set?
Do you know any good example of a DAO?
You are on the right track to build a DAO: the methods you listed should definitely be part of a DAO.
To answer your specific question, a DAO should not leak any database specific objects, it can leak some database concepts though as long as they are not specific to a database vendor.
So no, you should not return a MySQL result set. But you could create a generic result set that wraps a MySQL result set and that may work with higher level concepts (extracting whole objects instead of extracting columns).
Edit: My intent is not to lead you to actually build a result set wrapper, you could also simply return an array of objects like you initially suggested. This was just an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With