1. 程式人生 > 其它 >thinkphp5框架中在model層列印sql語句的方法

thinkphp5框架中在model層列印sql語句的方法

技術標籤:Thinkphp框架

thinkphp5框架中在model層列印sql語句的方法

model層

<?php

namespace app\common\model;

use think\Model;
use app\common\model\Base;

class News extends Base
{

    /**
     * 後臺自動化分頁
     * @param array $data
     */
    public function getNews($data = []) {
        $data['status']
= [ 'neq', config('code.status_delete') ]; $order = ['id' => 'desc']; // 查詢 $result = $this->where($data) ->order($order) ->paginate(); // 除錯列印sql語句 echo $this->getLastSql(); return $result; }

列印sql語句

echo $this->getLastSql();

在這裡插入圖片描述