php如何使用tp5查询数据总数

PhpPhp 2023-08-28 23:19:35 633
摘要: php使用tp5查询数据总数的方法:在tp5中,我们可以使用Db类进行数据库操作。要查询表中的数据总数,可以使用count()方法。下面是一个示例代码:<?phpnamespaceapp\index\controller;usethink\Controller;usethink\Db;...

php使用tp5查询数据总数的方法:

在tp5中,我们可以使用Db类进行数据库操作。要查询表中的数据总数,可以使用count()方法。

下面是一个示例代码:

<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends Controller
{
    public function index()
    {
        $count = Db::name('user')->count();
        echo 'User表中共有 '.$count.' 条数据';
    }
}