The limit method of 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 using paging queries. And ThinkPHP's limit method is compatible with all database driver classes.
The specific usage is as follows:
1. Limit the number of results:
For example, to get 10 users who meet the requirements, call the following:
$User = M('User'); $User->where('status=1')->field('id,name')->limit(10)->select();
limit method can also be used for write operations, such as updating 3 pieces of data that meet the requirements:
$User = M('User'); $User->where('score=100')->limit(3)->save(array('level'=>'A'));
2. Paging query:
is used for article paging query where the limit method is more commonly used, for example:
$Article = M('Article'); $Article->limit('10,25')->select();
means querying article data, 25 pieces of data starting from row 10 (it may also depend on the influence of where condition and order sorting, not to mention this for now).
After version 3.1, you can also use it like this:
$Article = M('Article'); $Article->limit(10,25)->select();
In addition, For large data tables, try to use limit to limit query results, otherwise it will cause large memory overhead and performance problems.