Guest User

Untitled

a guest
Dec 26th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. const USER = 'test';
  4. const PASS = 'test';
  5.  
  6. try {
  7.  
  8. $dbh = new PDO('mysql:host=localhost;dbname=test', USER, PASS, [
  9. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  10. ]);
  11.  
  12. $sql = '';
  13. $sql .= "SELECT * FROM demo WHERE 1=1 ";
  14. $sql .= "AND hint LIKE :f1 ESCAPE '/' ";
  15. $sql .= "OR hint LIKE :f2 ESCAPE '/' ";
  16.  
  17. $sth = $dbh->prepare($sql);
  18. $sth->bindValue(':f1', '2XXXX4/_%');
  19. $sth->bindValue(':f2', '%/_2XXXX4/_%');
  20. $sth->execute();
  21.  
  22. $result = $sth->fetchAll();
  23. echo "<pre>" .print_r($result, true). "</pre>";
  24.  
  25. $dbh = null;
  26. } catch (PDOException $e) {
  27. print "Error!: " . $e->getMessage() . "<br/>";
  28. die();
  29. }
Add Comment
Please, Sign In to add comment