Data Transfer Object is a heavily used design pattern used in the development of web applications requiring database interaction in J2EE. It makes the life of a developer highly easy in managing the data that is being transferred and provides a secured way of transferring the data between layers.
When i switch from J2EE to PHP and with the release of PHP5, it suddenly comes to my mind to use this concept along with Data Access Object pattern (which i will explain in my next post) from J2EE in PHP and it worked wonderfully for me to meet any level of complex applications.
What is a Data object?
First of all, we need to understand as what is a data object. A data object is a class representing a table in the database with the field names exactly same as database column names. It contains the getter and setter methods for these fields.
Let’s say i have a table called tbl_employee having columns as
- id (int 10)
- name ( varchar(50))
Now, the dataobject would typically look like
public class Employee()
{
var $id;
var $name;
public function getId()
{
return $this->id;
}
public function setId($tempId)
{
$this->id=$tempId;
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($tempName)
{
$this->name=$tempName;
return $this->name;
}Now the next point is about using it and see how helpful it would turn out to be. The following function interacts with the database thus assuming database connection is available.
public function getEmployeeList()
{
$employeeList = array();
$query = “select * from tbl_employee order by name”;
$result = mysql_query($query);
while ($row=mysql_fetch_array($result))
{
$tempEmployeeDO = new EmployeeDO();
$tempEmployeeDO->setId($row['id']);
$tempEmployeeDO->setName($row['name']);
$employeeList[count($employeeList)] = $tempEmployeeDO;
}
return $employeeList;
}
Thus the above function returns the list of employees containing data objects. On the front end you need to iterate through the list where each element is a DO and than use getter method to retrieve the values.
Start using it and you will realize that it makes your life pretty easy during development.
Enjoy!!
Ushainformatique Development Team
nice post. thanks.
great post as usual!
Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!
I was pleased to read this article, keep up the good work.
this post is very usefull thx!
Just want to say what a great blog you got here!
I’ve been around for quite a lot of time, but finally decided to show my appreciation of your work!
Thumbs up, and keep it going!
Cheers
Christian, iwspo.net
I would like to say “wow” what a inspiring post. This is really great. Keep doing what you’re doing!!
found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later
My cousin recommended this blog and she was totally right keep up the fantastic work!
i know i’m a little off topic, but i just wanted to say i love the layout of your blog. i’m new to the blogegine platform, so any tips on getting my blog looking good would be appreciated.
We very much loved the current comments. Please continue this mindblowing work. Thank You!!
Wow this is a great resource.. I’m enjoying it.. good article
Great information! I’ve been looking for something like this for a while now. Thanks!
I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.
Greetings, I like your website. This is a good site and I wanted to post a little note to let you know, good job! Thanks Meia
Louis Vuitton
louis vuitton
Yes… i also really like to visit new place, your idea is good.
Yes… i also really like to visit new place, your idea is good.
great experience, dude! thanks for this great
Articles wow… it’s very wonderful report.
Thank you for sharing I wish I could go somwhere.
it is very good share,thanks,and i like this blog
glad to read this information
Brilliant post. Just found it on Yahoo. Thank u for the useful information. Keep up the great work
Post very nicely written, and it contains useful facts. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement. Thanks for sharing with us.
http://soft-7.com
Hello, I love your article. This is a cool site and I wanted to post a note to let you know, great job! Thanks Jessica
Louis Vuitton
vuitton
Greetings, I enjoy your blog. This is a great site and I wanted to post a comment to let you know, nice job! Thanks kim
Louis Vuitton
vuitton
Hello This is a great blog keep your good work and thank you for hvar in with me So nice to hear frome you.Thanks!
You gave fantastic honest ideas here. I performed a research on the issue and discovered almost all peoples will agree with your Cartucce blog. How can I subscribe to RSS?
Sally, you are absolutely correct, it shows that you’re an authority on the subject. I admire someone that takes the pride you have and with your projecton of information. oSo when i actually do sit down to read material, I appreciate well written and organized blogs like this one. I have it bookmarked and will be back. Thanks.
A well written article. I’m an internet gamer and I’m always looking for news like this.
AOL led me to this blog post, and it is everything that I was looking for.
really very helping……very informative….thanks to give us this knowledge
I am going to bookmark this blogg on Mixx to get more clicks for you.
Hello, thank you very much for this post, cheers
Thanks for some great points there. I am kind of new to web surfing, so I printed this off to put in my file, any better way to go about keeping track of it then printing?
Nice site, I just dugg this keep up the good work!. . . . . .
Very nice and helpful information has been given in this article. I like the way you explain the things. Keep posting. Thanks. . .
Thank you so much for this valuable information. Very useful indeed. . . . .
it was very interesting to read.
I hope you will keep updating your content constantly as you have one dedicated reader here.
Guys, Great article and very very interesting blog. That’s one thing I’m really looking forward. Looking forward to reading more from you next week.
Once I started reading this post I couldn’t stop until I was finished, though it wasn’t precisely what I have been looking for, was a nice read though.
I really love going back to your site to read your story and see more pictures that are really taken with great care. . . . . .
Good share,you article very great, very usefull for us…thank you
Guys, Great article and very very interesting blog. That’s one thing I’m really looking forward. Looking forward to reading more from you next week.
I really like your site and i really appreciate the excellent quality content you are posting here for free for your online readers. Can you tell us which blog platform you are using?
awesome post. I have discovered for myself just how flexible WP is, as a hosting platform for your website. you literally have everything you need to publish a website at your fingertips, through WordPress. thanks.
This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It?s the old what goes around comes around routine. Did you acquired lots of links and I see lots of trackbacks??
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.
Thanks for some quality thoughts there. I am kind of new to the internet , so I printed this off to put in my file, any better way to go about keeping track of it then printing?
Very nice and helpful information has been given in this article. I like the way you explain the things. Keep posting. Thanks. . .