Hello. Recently began to study PDO Mysql. Faced such a question, I write a file of personal pages for users, and do a selection of the database. I wanted to clarify whether it is necessary to filter the $ _GET ['username'] variable or is it enough to run it through bindParam? Is it possible to get SQL Inj? Thank)
$stmt = $db->prepare('SELECT `id`, `username` FROM `accounts` WHERE `username` = :username LIMIT 1'); $stmt->bindParam(':username', $_GET['username'], PDO::PARAM_STR); $stmt->execute();
isset($_GET['username'])is at least needed to make sure that the variable is available at all. - Vismanid,usernameFROMaccountsWHEREusername=: username LIMIT 1'); $ stmt-> bindParam (': username', $ username, PDO :: PARAM_STR); $ stmt-> execute (); - VaDoSiQif (! isset($_GET['username'])) {exit('Пошли на фиг! С новым годом!');}at the beginning of the script that uses$_GET['username']PS Before using any data that came from the side, you need to check their presence as a minimum. As a maximum - drive through the validator. - Visman