Created
March 21, 2011 10:29
-
-
Save mattattui/879269 to your computer and use it in GitHub Desktop.
Using prepared statements in PDO
This file contains hidden or 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 | |
$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)) { | |
// ... | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also mentioned in https://lazycat.org/php-output-escaping.html