I wonder if I need to escape $_POST and/or $_GET arrays in PDO? (OOP)
Example:
<?php $name = $_POST['name']; ?>
What should I do to prevent "SQL Injection" with this? Thanks.
I wonder if I need to escape $_POST and/or $_GET arrays in PDO? (OOP)
Example:
<?php $name = $_POST['name']; ?>
What should I do to prevent "SQL Injection" with this? Thanks.
if you are using pdo you can use the prepare statement
Here you have good examples :
http://php.net/manual/en/pdo.prepare.php
PDO will escape for you the value before your query (with the prepare statement), so you don't have to worry about that.
A double NO.
What should I do to prevent "SQL Injection"
Every variable that is going into SQL query should be added via placeholder only, no matter if it coming from POST, GET or ATM wire transfer.
You should use prepared statements. Not only does PDO escape the values for you, but it makes the query string look a bit nicer too, and easier for maintenance later on down the line.
$sql = 'SELECT * FROM users WHERE id=?';
$dbh->execute(array("@p1", $_GET['blah']));
I use hash PHP when I need help with PDO they are a bit easier to understand.