Can a pattern matching expression be a SQL injection?
preg_match('/^[az\d-]+$/', $var) SQL query:
"SELECT `id` FROM `table` WHERE `col` = '$var'" Can a pattern matching expression be a SQL injection?
preg_match('/^[az\d-]+$/', $var) SQL query:
"SELECT `id` FROM `table` WHERE `col` = '$var'" Injections should not be, but it is better to use standard prepared expressions with placeholders. At least in order not to invent a new regular for the new incoming parameter.
Edited : With the performance of prepared expressions specifically in PHP, everything is difficult. Theoretically, they can give a win. It is necessary to take into account that usually the connection with the database is created anew with each http request and that by default pdo_mysql emulates the prepared statement on the client side.
If you know about it, then perhaps the speed will be an additional argument in favor of PS.
Source: https://ru.stackoverflow.com/questions/522535/
All Articles