diff --git a/examples/php-example.php b/examples/php-example.php index 381359f6..20d36b49 100644 --- a/examples/php-example.php +++ b/examples/php-example.php @@ -1,4 +1,4 @@ -getMessage(); +} # Perform the query -$query = sprintf("SELECT id, name from mytable WHERE name LIKE '%%%s%%' ORDER BY popularity DESC LIMIT 10", mysql_real_escape_string($_GET["q"])); +$query = sprintf("SELECT id, name from mytable WHERE name LIKE '%%%s%%' ORDER BY popularity DESC LIMIT 10", +mysql_real_escape_string($_GET["q"])); + +$stmt = $dbh->prepare("SELECT id, name from mytable WHERE name LIKE ? ORDER BY popularity DESC LIMIT 10"); +$stmt->bindValue(1,'%%%'.htmlspecialchars($_GET["q"]).'%%%'); +$stmt->execute(); $arr = array(); -$rs = mysql_query($query); # Collect the results -while($obj = mysql_fetch_object($rs)) { +while($obj = $stmt->stmt->fetch(PDO::FETCH_OBJ)) { $arr[] = $obj; }