mweldan Posted February 22, 2013 Share Posted February 22, 2013 Hi, Please see this: https://github.com/weldan/karipap/blob/master/karipap.class.php I am trying to create data access object, but somehow confused between data access object and abstraction layer . can someone explain about it? thanks Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/ Share on other sites More sharing options...
AyKay47 Posted February 22, 2013 Share Posted February 22, 2013 That is a data access abstraction layer in interface form. To keep it simple, a DAO separates the business logic from the persistence layer and provides the basic CRUD operations at an object level. The most basic question when beginning to think about DAO's is what specific object are you creating a DAO pattern for? Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414078 Share on other sites More sharing options...
mweldan Posted February 22, 2013 Author Share Posted February 22, 2013 I want to simplify create,retrieve,update,delete process using pdo the class later can be extend to provide methods for specific object similar to model concept on common mvc web frameworks. eg: User, Item I have no idea if I get lost on understanding this pattern. Is what I am doing is on right track? Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414082 Share on other sites More sharing options...
AyKay47 Posted February 22, 2013 Share Posted February 22, 2013 PDO is a persistence layer itself, simplifying a persistence layer is creating an persistence abstraction layer of your own and does not require an interface. Since you are wanting to implement PDO, you could either implement the inheritance method instead of a DAO, or create a UserDao class and an ItemDao class for example versus an interface and have them implement the PDO persistence abstraction layer that you are building currently. Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414112 Share on other sites More sharing options...
mweldan Posted February 23, 2013 Author Share Posted February 23, 2013 (edited) So interface it not required at all? Ok will remove it. Thanks I actually want to know about DAO, so I try to create one. It seems I have gotten far out from what I want to achieve. I did some google search about it and found someone else try to achieve same thing and name it as ORM (object relational mapper) . In your opinion, is it what I try to do now can be called as ORM? (or poor version of ORM?. Hehe ) And if can, I need examples for DAO in PHP if any. Thanks for your answer. Edited February 23, 2013 by mweldan Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414410 Share on other sites More sharing options...
AyKay47 Posted February 23, 2013 Share Posted February 23, 2013 Before I can adequately answer your questions and go off on a tangent about ORMs and DAOs, I first need to know what exactly it is that you are trying to achieve. I noted that you are attempting to create a DAO, but is that the root of what you are trying to do or is there something else? Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414434 Share on other sites More sharing options...
mweldan Posted February 23, 2013 Author Share Posted February 23, 2013 The root of what I am trying to do is to understand what DAO is and how to implement that in PHP. take a look at this: http://blog.chrisdlangton.com/index.php?article=50 how this different than this: https://github.com/j4mie/idiorm Thank you for your answer Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414452 Share on other sites More sharing options...
KevinM1 Posted February 23, 2013 Share Posted February 23, 2013 The first is a DAO, the second is an ORM. A DAO (Data Access Object) is essentially an OO interface (meaning a way to interact with and not the language construct interface) to a database. It's methods are generally your basic CRUD and anything else not app-specific. An ORM (Object Relational Mapper) is a mechanism to translate objects into database data and back again. So, let's say you had a User object that had a person's name, age, gender, and a list of groups they belonged to (for site permissions or whatever). An ORM would map (the 'M') that data to actual database rows and columns. An ORM is more complex than a DAO because it needs to keep track of how the data in a particular object is related. In my User example, the list of groups would come from another database table than the other User information. An ORM could use/extend a DAO. The second link you gave mashes the two into one class, which is simple, but not necessarily flexable. Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414455 Share on other sites More sharing options...
mweldan Posted February 23, 2013 Author Share Posted February 23, 2013 So I think what I want is actually ORM. This is what I want to do: 1. create a class to simplify usage of PDO, have some functions to make it easy to query database 2. extend that class in a class that specifically uses for objects or tables. as far i understand similar to what model in mvc structure (sorry because this is the only one i familiar with) Thank you for your answer. Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414457 Share on other sites More sharing options...
AyKay47 Posted February 23, 2013 Share Posted February 23, 2013 Then it sounds like you want to create a persistence abstraction layer on top of the PDO layer and create DAOs that "implement" the custom persistence layer. DAOs can be as large or as small as you want them to be, just remember that they should only handle the basic CRUD operations for a particular object. Quote Link to comment https://forums.phpfreaks.com/topic/274807-can-this-be-called-as-data-access-object-class/#findComment-1414474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.