What we want to introduce to you today is:1.
Condition: PHP magic_quotes_gpc = off
The string written to the database has not been filtered. The strings read from the database are not processed.
Data: bytes $ data = "snow" ''sun "; (four consecutive single quotes between snow and sun ).
Operation: Write the string: "snow" ''sun "to the database,
Result: if an SQL statement error occurs, mysql cannot complete the SQL statement successfully and fails to write data to the database.
Database storage format: no data.
Output Data Format: no data.
Note: An SQL statement error occurs when unprocessed single quotes are written to the database.
2.
Condition: PHP magic_quotes_gpc = off
The string written to the database is processed by the addlashes () function. Strings read from the database are not processed.
Data: bytes $ data = "snow" ''sun "; (four consecutive single quotes between snow and sun ).
Operation: Write the string: "snow" ''sun "to the database,
Result: The SQL statement is successfully executed and data is successfully written to the database.
Database storage format: snow "'' sun (same as input)
Output Data Format: snow "'' sun (same as input)
Note: The addslashes () function converts single quotes to escape characters so that SQL statements are successfully executed,
However, 'the database does not store data into the database. The database stores snow. ''' sun, not the snow ''' we imagined.
3.
Condition: PHP magic_quotes_gpc = on
The string written to the database has not been processed. Strings read from the database are not processed.
Data: bytes $ data = "snow" ''sun "; (four consecutive single quotes between snow and sun ).
Operation: Write the string: "snow" ''sun "to the database,
Result: The SQL statement is successfully executed and data is successfully written to the database.
Database storage format: snow "'' sun (same as input)
Output Data Format: snow "'' sun (same as input)
Note: PHP magic_quotes_gpc = on converts single quotes to escape characters so that the SQL statement is successfully executed,
However, 'the database does not store data into the database. The database stores snow. ''' sun, not the snow ''' we imagined.
4.
Condition: PHP magic_quotes_gpc = on
The string written to the database is processed by the addlashes () function. Strings read from the database are not processed.
Data: bytes $ data = "snow" ''sun "; (four consecutive single quotes between snow and sun ).
Operation: Write the string: "snow" ''sun "to the database,
Result: The SQL statement is successfully executed and data is successfully written to the database.
Database storage format: snow ''' sun (escape characters added)
Output Data Format: snow ''' sun (escape characters added)
Note: PHP magic_quotes_gpc = on converts single quotes to escape characters so that the SQL statement is successfully executed,
Addslashes converts the single quotes that will be written into the database into ', and the latter conversion is written as data
Database. The database stores snow ''' sun
Summary:
1. For PHP magic_quotes_gpc = on,
We may not use the string data of the input or output database
The operation of addslashes () and stripslashes () will also display the data normally.
If you perform addslashes () processing on the input data,
In this case, you must use stripslashes () to remove unnecessary backslash.
2. PHP magic_quotes_gpc = off
You must use addslashes () to process the input data, but you do not need to use stripslashes () to format the output.
Because addslashes () does not write the backslash together into the database, it only helps mysql to complete SQL statement execution.
Supplement:
PHP magic_quotes_gpc: WEB Client Server; Time: When the request starts, for example, when the script is running.
Magic_quotes_runtime: The data read from the file, the exec () execution result, or the result obtained from the SQL query. function time: the data generated every time the script accesses the running state.