Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created September 11, 2012 04:25
Show Gist options
  • Save ajcrites/3695946 to your computer and use it in GitHub Desktop.
Save ajcrites/3695946 to your computer and use it in GitHub Desktop.
Unnamed vs. Named prepared statements in PDO
//UNNAMED
$query = "SELECT userid FROM t1 WHERE (username = ? OR useremail = ?)
AND usertoken = ?";
$prepared_statement = $db_connection->prepare($query);
$prepared_statement->execute(array($_POST['login'], $_POST['login'],
$_POST['token'])
);
//NAMED
$query = "SELECT userid FROM t1 WHERE (username = :login
OR useremail = :login) AND usertoken = :token";
$prepared_statement = $db_connection->prepare($query);
$prepared_statement->execute(array('login' => $_POST['login'],
'token' => $_POST['token'])
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment