如何顯示thinkphp執行的語句

來源:互聯網
上載者:User
控制區器是這樣寫的
function checkLogin(){$condition['employeeno'] = $_REQUEST['employeeno'];$condition['password'] = $_REQUEST['password'];$model = M("Employeeinfo");$results = $model->where($condition)->select(); sql($model);if($results){if(trim($results[0]['Password'])==$condition['password']){echo "{success:true,msg:'OK'}";Session::set('employeeno','employeeno');Session::set('userinfo',$results[0]);return;}}echo "{success:true,msg:'登入帳號不存在互或密碼錯誤!'}";}


我登入了38次,均未成功(提示登入帳號不存在互或密碼錯誤),log中也沒提示錯誤。
為了協助我核對資料,我要把sql語句,印表機出,如:select employeeno,password from
我使用vamp($model)
也顯示不出來。


回複討論(解決方案)

開啟debug,檢查sql語句,複製sql語句在資料庫中執行,看看有沒有結果

$model = M("Employeeinfo");
$results = $model->where($condition)->select();
echo $results->getlastSql();

加上

$condition['_logic'] = 'AND';
$model = M("Employeeinfo");
$results = $model->where($condition)->select();
$model->getlastSql();

看看呢

加上

$condition['_logic'] = 'AND';
$model = M("Employeeinfo");
$results = $model->where($condition)->select();
$model->getlastSql();

看看呢



這位兄台的才是正確的!

你select方法裡面加上個false就好了。他就不執行SQL語句了。轉而把SQL語句列印出來。
$model = M("Employeeinfo")->select( false);

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.