sprintf php sprintf function to make your SQL operation more secure

Source: Internet
Author: User
Tags sprintf
$bookSQL =sprintf ("UPDATE book SET pass=%s WHERE id=%d",
Getsqlvaluestring ($_post[' list '], "text"),
Getsqlvaluestring ($_get[' id '], "int"));
Getsqlvaluestring This function can be replaced by other functions
But here's the function of sprintf () in the SQL statement! It's relatively safe, like the ID where we can use%d.
Or a lot of SQL operations, use this
$Result = $db->query ($bookSQL) or Die (Mysql_error ());
Here is a description of the function sprintf:
Reference
sprintf
Formats the string.
Syntax: string sprintf (string format, mixed [args] ...);
return value: String
Function type: Data processing
Content Description
This function is used to format a string. The parameter format is the converted form, starting with the percent sign% and ending with the conversion character. The converted format consists of the
Fill the blanks with characters. 0 words means blank space is 0, space is the default value, the space is left.
The Alignment method. The default value is right-aligned, and the minus table is aligned to the left.
Field width. To the minimum width.
Accuracy. Refers to the number of floating-point digits after the decimal point.
Type, see the following table% print percent symbol, do not convert.
b integer turns into binary.
The c integer is converted to the corresponding ASCII character.
D integers are turned into 10.
The F-Times precision number is converted to floating point numbers.
o integers are turned into octal.
The s integer is converted into a string.
The x integer is converted to lowercase 16 rounding.
X integers are converted to uppercase 16 rounding.

The above describes the sprintf php sprintf function to make your SQL operations more secure, including the sprintf aspect of the content, I hope that the PHP tutorial interested in a friend to help.

  • 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.