Home >PHP Framework >ThinkPHP >Is there preprocessing in thinkphp?
There is preprocessing in thinkphp. The "ThinkPHP3.1" version adds support for preprocessing conditional strings, making ORM security more secure. Methods: 1. Use the where method to preprocess string conditions; 2. Use the query and execute methods to preprocess native SQL query methods.
The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.
Is there preprocessing in thinkphp
The previous ThinkPHP3.0 version has an array method The query conditions will be security filtered (this is because 3.0 forces the use of field type detection, so the array query conditions will be forced to be converted to the set type of the field), but version 3.0 does not support security filtering of string conditions. The ThinkPHP 3.1 version adds support for preprocessing conditional strings, making the security of ORM more guaranteed.
1. Use the where method
The where method of the Model class supports string condition preprocessing, usage method:
$Model->where("id=%d and username='%s' and xx='%f'",array($id,$username,$xx))->select();
or use it directly:
$Model->where("id=%d and username='%s' and xx='%f'",$id,$username,$xx)->select();
If the $id variable comes from user submission or URL address, if the incoming type is a non-numeric type, it will be forced to be formatted into a numeric format before querying.
The string preprocessing format type supports specifying numbers, strings, etc. For details, please refer to the parameter description of the vsprintf method.
2. Use query and execute methods
In addition to where conditions, the preprocessing mechanism is also supported for native SQL query methods, for example:
$Model->query("SELECT * FROM think_user WHERE id=%d and username='%s' and xx='%f'",array($id,$username,$xx));
The execute method of the model also supports the preprocessing mechanism like the query method.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of Is there preprocessing in thinkphp?. For more information, please follow other related articles on the PHP Chinese website!