以往的ThinkPHP3.0版本对数组方式的查询条件会进行安全过滤(这是由于3.0强制使用了字段类型检测,所以数组方式的查询条件会强制转换为字段的设定类型),但是3.0版本并不支持字符串条件的安全过滤。而ThinkPHP3.1版本则增加了对条件字符串进行预处理的支持,让ORM的安全性更加得以保证。
一、使用where方法
Model类的where方法支持字符串条件预处理,使用方式: $Model->where("id=%d and username='%s' and xx='%f'",array($id,$username,$xx))->select();
或者直接使用:
$Model->where("id=%d and username='%s' and xx='%f'",$id,$username,$xx)->select();
如果$id变量来自用户提交或者URL地址的话,如果传入的是非数字类型,则会强制格式化为数字格式后进行查询操作。
字符串预处理格式类型支持指定数字、字符串等,具体可以参考vsprintf方法的参数说明。
二、使用query和execute方法
除了where条件外,对原生SQL查询方式也支持预处理机制,例如:
$Model->query("SELECT * FROM think_user WHERE id=%d and username='%s' and xx='%f'",array($id,$username,$xx));
模型的execute方法也和query方法一样支持预处理机制。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
