thinkphp 預處理機制

where方法使用字符串條件的時候,支持預處理(安全過濾),並支持兩種方式傳入預處理參數,例如:
  1. $Model->where("id=%d and username='%s' and
  2. xx='%f'",array($id,$username,$xx))->select();
複製代碼
或者
  1. $Model->where("id=%d and username='%s' and
  2. xx='%f'",$id,$username,$xx)->select();
複製代碼
模型的query和execute方法 同樣支持預處理機制,例如:
  1. $model->query('select * from user where id=%d and status=%d',$id,$status);
複製代碼
或者
  1. $model->query('select * from user where id=%d and
  2. status=%d',array($id,$status));
複製代碼

execute方法用法同query方法。




%s -- 表示字段串
%d -- 表示整形數字
%f -- 表示浮點數


發佈了22 篇原創文章 · 獲贊 12 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章