数据库API常用片段
注册

数据库API常用片段

求某一列数据和

table.contentsviews列数据之和,本身typecho并不存在views列,这里只是举个例子

$db = \Typecho\Db::get();
echo $db->fetchObject($db->select(['SUM(views)' => 'Count'])->from('table.contents')
->where('type = ?', 'post'))->Count;

统计行数

事例为根据cid统计文章数量

$db = \Typecho\Db::get();
return $db->fetchObject($db->select(['COUNT(cid)' => 'num'])
            ->from('table.contents')
            ->where('table.contents.type = ?', 'post'))->num;

泽泽社长 Last updated 2024-12-16 Created 2024-12-16 122

大纲
加载中