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

Does thinkphp have an orm?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-26 09:46:123525browse

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 数据库连接信息

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!

Statement:
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
Previous article:How to upgrade thinkphpNext article:How to upgrade thinkphp