Home  >  Article  >  Backend Development  >  sprintf php sprintf function makes your sql operations safer

sprintf php sprintf function makes your sql operations safer

WBOY
WBOYOriginal
2016-07-29 08:38:281433browse

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",
                                                             GetSQLValueString($_GET['id'],"int "));
GetSQLValueString This function can be replaced by other functions
But if the sprintf() function is used in the sql statement! It is relatively safer. For example, we can use %d for id
or when there are many sql operations, use this
$Result = $db->query($bookSQL) or die(mysql_error());
Add below the description of the sprintf function:
Quote
sprintf
Format 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 conversion format, starting with the percent sign % and ending with the conversion character. The converted formats include
fill-in-the-blank characters in sequence. If 0 , it means that the blanks are filled with 0; blanks are the default value, which means that the blanks are left alone.
Alignment. The default is right-aligned, with negative tables aligned left.
Field width. is the minimum width.
Accuracy. Refers to the number of floating point digits after the decimal point.
Type, see the table below % prints the percentage symbol without conversion.
b Convert integer to binary.
c Convert integers to corresponding ASCII characters.
d Convert integer to decimal.
f times precision numbers are converted into floating point numbers.
o Convert integers to octal.
s Convert integer to string.
x Convert integer to lower case hexadecimal.
X Convert integer to uppercase hexadecimal.

The above has introduced the sprintf php sprintf function to make your sql operations safer, including sprintf content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn