我们在编码的过程中,有时候程序返回的结果不容易排错,这时候就有必要输出原生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 之后的字段为主

相关文章:

  • 2022-12-23
  • 2021-05-25
  • 2022-01-03
  • 2021-07-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-26
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案