
Originally Posted by
Banana Man
I have just started using PDO Prepared Statements and was wondering if i still need to escape quotes and double quotes when inserting data in my MySQL database?
Short answer: no. It's Ok, you're safe, if you are really using preparedStatements
Example:
PHP Code:
<?php
$color = $_POST['color'];
$calories = $_POST['calories'];
// NOT OK, $color still may have injections
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :cal AND colour = "' . $color . '"
');
$sth->execute(array( ':cal' => $calories ));
$red = $sth->fetchAll();
// OK - you're safe
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :cal AND colour = :col
');
$sth->execute(array( ':cal' => $calories, ':col' => $color ));
$red = $sth->fetchAll();
?>
Bookmarks