[数据模型]-查询`date`类型字段最大日期
~~~
/**
* 返回数据表date最新日期
*
* @return int 当前id最大值
*/
public function getRecentDate()
{
try {
$res = $this->field('date')->order('date desc')->limit(1)->select();
return $res ? $res[0]->date : null;
} catch (\Exception $e) {
throw new \think\Exception('异常消息:' . $e->getMessage());
}
}
~~~
[数据库类]-查询日期最大值
~~~
<?php
namespace app\index\model;
use app\common\model\RemoteModel;
use think\Db;
use think\Model;
class Retention extends RemoteModel
{
protected $connection = ['prefix' => 'acc_dragon_'];
/**
* 初始化
*
* @return void
*/
protected function initialize()
{
parent::initialize();
$this->table = 'acc_dragon_retention';
}
/**
* 返回数据表主键ID最大值
*
* @return int 当前id最大值
*/
public function getRecentDate()
{
try {
$sql = "select date from `acc_dragon_retention` order by `date` desc limit 1";
$res = Db::query($sql);
return $res ? $res[0]['date'] : null;
} catch (\Exception $e) {
throw new \think\Exception('异常消息:' . $e->getMessage());
}
}
~~~