thinkphp 预处理机制

来源:互联网 发布:java 读取 tar.gz文件 编辑:程序博客网 时间:2024/05/13 14:04
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 -- 表示浮点数


0 0