The limit Method of the ThinkPHP CURD method is also one of the coherent operation methods of the model class. It is mainly used to specify the number of queries and operations, especially when querying by page. The limit Method of ThinkPHP can be compatible with all database driver classes.
Its usage is as follows:
1. Limit the number of results:
For example, you can obtain 10 users that meet the requirements by calling the following code:
$ User = M ('user'); $ User-> where ('status = 1')-> field ('Id, name')-> limit (10) -> select ();
The limit method can also be used for write operations, such as updating three data entries that meet the requirements:
$ User = M ('user'); $ User-> where ('score = 100 ')-> limit (3) -> save (array ('level' => 'A '));
2. Paging query:
It is a commonly used limit Method for querying articles by page. For example:
$ Article = M ('Article'); $ Article-> limit ('10, 25')-> select ();
It indicates to query the article data. The 25 pieces of data starting from the first row of the article (may also depend on the influence of the where condition and order sorting. This is not mentioned at the moment ).
After version 3.1, you can also use:
$ Article = M ('Article'); $ Article-> limit (10, 25)-> select ();
In addition,For large data tables, use limit to limit query results. Otherwise, large memory overhead and performance problems may occur.