Created
May 24, 2013 22:04
-
-
Save psdtohtml5/5646820 to your computer and use it in GitHub Desktop.
PHP: PDO Prepared Statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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