Introduction to the query condition preprocessing of ThinkPHP3.1 new features _php instance

Source: Internet
Author: User
The previous ThinkPHP3.0 version of the query condition for the array method is safe filtering (this is because the 3.0 enforces the use of field type detection, so that the query conditions for arrays are cast to the set type of the field), but the 3.0 version does not support security filtering of string conditions. The ThinkPHP3.1 version adds support for preprocessing of conditional strings, which makes ORM security more secure.

First, use the Where method

The Where method of the Model class supports preprocessing of string conditions using the following methods: $Model->where ("id=%d and Username= '%s ' andxx= '%f '", Array ($id, $username, $xx))- >select ();

or directly using:

$Model->where ("id=%d and Username= '%s ' and xx= '%f '", $id, $username, $xx)->select ();

If the $id variable comes from a user commit or URL address, if the incoming non-numeric type is forced to be formatted as a number format, the query operation is performed.

String preprocessing format types support specifying numbers, strings, and so on, so you can refer to the parameter descriptions of the vsprintf method.

Ii. using the query and Execute methods

In addition to the Where condition, the preprocessing mechanism is supported for native SQL queries, such as:

$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 supports the preprocessing mechanism as well as the query method.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.