Home » Php » php – What is an ORM in a web application?

php – What is an ORM in a web application?

Posted by: admin July 12, 2020 Leave a comment

Questions:

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

How to&Answers:

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.

Answer:

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

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

Answer:

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!

Answer:

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

Answer:

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.

Answer:

ORM is a Wikipedia article on Object Relational mapping.

Answer:

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