Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created May 24, 2013 22:04
Show Gist options
  • Save psdtohtml5/5646820 to your computer and use it in GitHub Desktop.
Save psdtohtml5/5646820 to your computer and use it in GitHub Desktop.
PHP: PDO Prepared Statement
<?php
// PDO Prepared statements
try {
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM myTable WHERE id = :id');
$stmt->execute(array('id' => $id));
while($row = $stmt->fetch()) {
print_r($row);
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment