I'm relatively new to PDO and i have written the following block of code:
$id = $_GET['id'];
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
foreach($db->query("SELECT id,name FROM names where id = '$id' ") as $row) {
echo "<p>", ($row['name']), "<br>";
}
My uncertainties are:
- is it safe to OMIT mysql_real_escape_string in the first line since i'm using PDO
- is it safe to run the query as above without using bind values.
Thanks