Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created March 21, 2011 10:29
Show Gist options
  • Save mattattui/879269 to your computer and use it in GitHub Desktop.
Save mattattui/879269 to your computer and use it in GitHub Desktop.
Using prepared statements in PDO
<?php
$db = new PDO('mysql:host=hostname;dbname=defaultDbName',
'username', 'password',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$query = 'SELECT * FROM my_table WHERE title = :title';
$stmt = $db->prepare($query);
$stmt->bindValue(':title', $myTitle);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// ...
}
?>
@mattattui
Copy link
Author

@mattattui
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment