Home > Backend Development > PHP Problem > What does php's ORM mean?

What does php's ORM mean?

青灯夜游
Release: 2023-03-15 15:18:01
Original
4496 people have browsed it

In PHP, the full name of ORM is "Object-Relational Mapping", which means "object-relational mapping". Simply put, it is a mapping between the object model and the relational model; the main purpose of ORM is to convert the object model into The represented objects are mapped to the SQL-based relational model database structure.

What does php's ORM mean?

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

What does orm mean?

  • O = Object

  • ##RM->Relational Mapping

It is Object-Relationl Mapping. Simply put, it is a mapping between the object model and the relational model.

What idea does ORM represent:

  • Database table (table) --> Class (class)

  • Record (record, row data)–> Object (object)

  • Field (field)–> Object’s attribute (attribute)

Its function is to make a mapping between the relational database and the object. In this way, when we specifically operate the database, we no longer need to deal with complex SQL statements. We only need to operate it as we usually operate objects. That's it.

For example: to obtain an article, the traditional way is to first execute a sql to retrieve the data

select * from post where id = 1
Copy after login

and then output the title and content using

echo $post['title']; echo $post['content'];
Copy after login

The above code encounter People with object-oriented obsessive-compulsive disorder will struggle to death.

So they came up with this thing, getting an article in ORM can be like this:

$post = postTable::getInstance()->find(1);#会再内部执行select * from post where id = 1
Copy after login

Then output:

echo $post->getTitle();
echo $post->getContent();
Copy after login

Mom no longer has to worry about my obsessive-compulsive disorder ^_^

Advanced application, articles and categories are one-to-many relationships, articles and tags are many-to-many relationships

$cate = $post->getCategory(); //获取文章分类
echo $cate->getName(); //获取分类名 $tags = $post->getTags(); //获取一个文章的所有标签
Copy after login

Is it possible to get us without writing a single sql? All the data needed? Using ORM, you can implement applications without writing SQL at all. ORM does all this for us.

In addition, ORM can also isolate the underlying database layer. We don't need to care whether we are using mysql or other relational databases.

The ORM I know: doctrine and prop

In addition to ORM, there is also ODM, that is, object document mapping, object document mapping, used when using a document database such as mongodb

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What does php's ORM mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template