1
Well I have 2 ways to prevent sql inject, are they:
first
$input = $conexao->real_escape_string($input);
2nd
$input = filter_var ($input, FILTER_SANITIZE_SPECIAL_CHARS);
Query
select * from cadastro where nome = '".$input."' LIMIT 1
What is the best way?
The real_escape_string requires mysql or php server resource?
more here https://wiki.locaweb.com.br/pt-br/Como_se_proteger_do_SQL_Injection
– user60252
The
FILTER_SANITIZE_SPECIAL_CHARSfor me is terrible. It will convert other information like the<,>and even the&. In my opinion the database should store all the original content and use thehtmlentites(orhtmlspecialchars) in the output of the information, never in the input. Also, if using theFILTER_SANITIZE_SPECIAL_CHARSyou will spend a<for<, then you’ll make ajson_encodeof a value<, doesn’t make any sense. Imagine that my username is<dev>, you will get the information from<dev&lr;. About "consuming resources", everything consumes. :)– Inkeliz