Let's say I want to select records where Id = 30
. Prepared statements allow two ways of binding parameters:
question marks
$id = 30;
$q = $conn->prepare("SELECT * FROM pdo_db WHERE id > ?");
$q->execute(array($id)); // Here above ID will be passed
named parameters
$sth = $conn->prepare("SELECT `id`, `title` FROM `pdo_db` WHERE `id` > :id");
$sth->execute(array(
':id' => 30
));
Both are working fine and give accurate results but I am not able to get the exact differences between these two nor when I should use one or another?