Guest User

Untitled

a guest
Jun 20th, 2017
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2. $method = "GET";
  3.  
  4.  
  5. $str="";
  6. if($_SERVER["REQUEST_METHOD"]== $method)
  7. {
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "pranay";
  11. $dbname = "myDB";
  12.  
  13. $str = $_GET['q'];
  14. // echo $qry;
  15.  
  16. try {
  17. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  18. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. $qry = "SELECT firstname, lastname FROM LoginPDO where firstname like '%$str%'; ";
  20. $stmt = $conn->prepare($qry);
  21. // $stmt->bindParam(":querystring", $str);
  22. $stmt->execute();
  23. // echo $stmt->rowCount();
  24. // echo $stmt->debugDumpParams();
  25. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  26. if($result){
  27. $results = $stmt->fetchAll();
  28. header('Content-Type: application/json');
  29. echo json_encode($results);
  30. }else
  31. echo " no resutl fodd";
  32.  
  33. }
  34. catch(PDOException $e) {
  35. echo "Error: " . $e->getMessage();
  36. }
  37. $conn = null;
  38.  
  39.  
  40. }
Add Comment
Please, Sign In to add comment