tp3、tp5 输出上一次sql语句

我们在编码的过程中,有时候程序返回的结果不容易排错,这时候就有必要输出原生sql语句来便于我们检查。

目前整理了TP3,和TP5的输出方式

TP3

M()->getLastSql();

 

TP5

Db::getLastSql();

 

另外TP3 Model 的基本用法,在Model文件夹下新建 ContentViewModel.class.php

<?php

    class ContentViewModel extends ViewModel {

        public $viewFields = array(
            'Content' => array('content_id', 'title', 'word_count'),
            'Contents' => array('content', '_on' => 'Content.content_id=Contents.content_id'),
        );

    }
    

假如在输出的时候要使用 as ,改变名字。

那么我们在控制器层

D('ContentView')->where($where)->field('number as word_count')->order('num asc')->select();
 
使用field,处理需要as的字段,需要注意的一点是修改完毕field之后,也要修改model(假如是先写model的话)字段以控制器as 之后的字段为主
posted @ 2020-03-11 11:54  super久违  阅读(1617)  评论(0编辑  收藏  举报