调试CRME后台的SQL语句(ThinkPHP6)

问题描述

写代码肯定有失误的时候,当查询参数出错时,如何输出错误信息呢?以前用thinkphp5在报错误的时候,可以通过DB::select(false)直接返回错误脚本,但是现在不可以了,会抛出异常,这样如何处理呢?

解决办法

代码是CRMEB下的,使用Dao进行处理

<?php
namespace app\common\dao\store;

use app\common\dao\BaseDao;
use app\common\model\store\StoreCategory as model;
use think\Log;

class StoreCategoryDao extends BaseDao
{
    private $log;

    public function __construct(Log $log)
    {
        $this->log = $log;
    }

    public function getModel(): string
    {
        return model::class;
    }

    public function test(?int $merId,$field,$value,$except = null)
    {
        $query = $this->getModel()::getDB();
        try {
            // 故意让脚本出错
            $lcc = ($query)->where(["xxxxxxxxx" => 171])->select(false);
        } catch (\Throwable $th) {
            $sql = ($query)->getLastSql();
            $this->log->error("StoreCategoryDao.test:".$sql);
        }
        return $data;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值