I have been researching into PDO's bindValue(). I know that preparing my SQL statements with PDO is keeping SQL injections from happening.
Code Example:
$stmt = $dbh->prepare('SELECT * FROM articles WHERE id = :id AND title = :title'); $stmt->bindValue(':id', PDO::PARAM_INT); $stmt->bindValue(':title', PDO::PARAM_STR); $stmt->execute(); By binding the ID as a number, and the Title was a string, we can limit the damage done when someone tries to do an SQL injection within the code.
Should we always bind our values with a PDO::PARAM_ so we can limit what can be pulled from the database in an SQL injection? Does this add more security with PDO when doing our bindValue()?
LIMITas an int the query won't react like you think (I can't remember if it fails or if it ignores it).bindValue? Leaving our thePDO::PARAM_argument? Or entirely forgoing theprepareAPI?PDO::PARAM_INTfor a number or can I survive with the defaultPDO::PARAM_STRthat's chosen if I don't select a param type? I realize it adds''s around the numbers, but does it really matter?".