ThinkPHP 5 limit()方法
2023-03-29 23:03:03
309
{{single.collect_count}}
WebsiteModel为自定义模型

use app\ciyuan_back\model\Website as WebsiteModel;

参数为n

n为正整数

$result = WebsiteModel::limit(1)->select();

显示1条记录

$result = WebsiteModel::limit(10)->select();

显示10条记录

不传参

$result = WebsiteModel::limit()->select();

报错:Missing argument 1 for think\db\Query::limit()

参数为0

$result = WebsiteModel::limit(0)->select();

显示所有记录

如果想查询所有记录,可以直接使用 $result = WebsiteModel::select();。

参数为-1

$result = WebsiteModel::limit(-1)->select();
报错:SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 1








回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}