Skip to content

Instantly share code, notes, and snippets.

@scottsappen
Created July 1, 2013 15:24
Show Gist options
  • Save scottsappen/5901807 to your computer and use it in GitHub Desktop.
Save scottsappen/5901807 to your computer and use it in GitHub Desktop.
PHP MySQL PDO sql injection safety
$pdo = new PDO('mysql:dbname=your_database;host=localhost', $username, $password);
//don't use whatever the user typed in, use a variable
$stmt = $pdo->prepare('SELECT * FROM MyGuestBook WHERE firstName = :firstName');
//that variable is then assigned to whatever the user typed in, but it's escaped and treated safely
$stmt->execute(array(':firstName' => $firstName));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment