Home > PHP Framework > ThinkPHP > Does thinkphp have an orm?

Does thinkphp have an orm?

爱喝马黛茶的安东尼
Release: 2019-08-26 09:46:12
Original
3579 people have browsed it

Does thinkphp have an orm?

THinkPHP is a relatively representative PHP development framework in China and supports the MVC development model. ThinkPHP's ORM (Object Relation Mapping) is a storage access layer for developers to use database development. The framework design picture is as follows:

Does thinkphp have an orm?

thinkPHP ORM framework adopts Active Record mode ( (referred to as AR) to design and implement.

Related recommendations: "ThinkPHP Tutorial"

What is Active Record mode?

is to use an AR class to associate a table in the database. Each AR object corresponds to a row of data in the table; the attributes of the object are mapped to the corresponding columns of the data row.

For example, a Customer AR class is associated with the customer table in the database, and the name attribute of the AR class represents the field named name in the customer table.

In thinkPHP, the base class of all AR classes is the Model class. The Model class is associated with the table in the database by name. The constructor of the Model class is as follows:

public function __construct($name='',$tablePrefix='',$connection='')
@param string  $name 模型名称
* @param string $tablePrefix 表前缀
* @param mixed  $connection 数据库连接信息
Copy after login

Data CURD of the Model class (create, update, retrieve, delete) operations are implemented through the concrete implementation of the database abstract class Driver, so that MySQL or Oracle can be conveniently used through configuration.

Through this design implementation, the following benefits can be obtained:

1. Whether the specific database is MySQL, Oracle, or switching from MySQL to Oracle, the code above the driver implementation does not Will be affected in any way;

2. The database table is mapped to the AR class, and the CURD operation of the database is interpreted and executed by the AR class, which is in line with the object-oriented design idea; and it is separated from the writing of specific SQL statements, and the code More concise and less error-prone.

The above is the detailed content of Does thinkphp have an orm?. 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