开发者

What is an ORM in a web application?

开发者 https://www.devze.com 2022-12-18 04:30 出处:网络
I recently got a reply from a server company asking if we are using an ORM in our applicationwhich does all the work of sifting application side (like Rails) or if we write reams of SQL, embedded func

I recently got a reply from a server company asking if we are using an ORM in our application which does all the work of sifting application side (like Rails) or if we write reams of SQL, embedded functions etc which would make the database server do the processing for you.

Can anyone explain what is meant by this. Our web application is made up of PHP scripts with functions that make calls to the database to retrieve rows of data, then PHP processes these rows as needed to return results to the user.

thanks开发者_开发技巧


It basically makes your database tables appear like objects on the PHP side of your site so you can easily manipulate data.

For example if you have a User table, getting this user's name is as easy as doing: $myUser->getName();

adding a new user in your database would be:

$myUser = new User();
$myUser->setName('John Doe');
$myUser->save();

Of course this is pseudo code (actually PHP Symfony/Doctrine code), but it's a simple example so you get the point.


An ORM is an abstraction that is supposed to simplify working with a relational database in an object oriented language. It's basically a set of classes and methods that let you create, retrieve and update data without using SQL directly.

For instance instead of writing $result=mysql_query('select * from sandwiches where color='green' and size='2');

you can use an interface like $result=$sandwiches->get('color'=>'green',=>'size'=>'2');

and the ORM turns this into SQL and executes the query, taking care of joins, etc.

Popular PHP ORMs are Doctrine and Propel

If you don't know whether you're using one, than it's pretty unlikely that you are!


It is an Object Relational Mapping. See link to wikipedia below.

http://en.wikipedia.org/wiki/Object-relational_mapping


ORM is Object Relational Mapper. which maps the java objects to the database tables and lets you perform some database transactions thorough your code. EX of ORM tools are like Hibernate, Ibatis ..


ORM is used for Mapping your database objects to your application objects.

In a simple application using ORM, you should have functions that gets/sets data from/to DB should return appropriate application object/objects.


ORM is a Wikipedia article on Object Relational mapping.


Object Relational Mapping is an easy way of mapping Database objects ( tables, views ... ) to classes/objects in OOPL. Hibernate and NHibernate are a few examples of ORM. it does all the tedious task of handling and mapping result sets..

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号