Advertisement
Guest User

Untitled

a guest
Aug 7th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. $servername = "mysql8.000webhost.com";
  2. $username = "removed";
  3. $password = "removed";
  4. $dbname = "removed";//I removed them cause, you know security matters hahaha
  5.  
  6.  
  7. try {
  8. $connection = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9. $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10. }
  11. catch(PDOException $e)
  12. {
  13. die("OOPs something went wrong");
  14. }
  15.  
  16. <?php
  17.  
  18. if(isset($_POST['searchQuery']))
  19. {
  20. require_once('config.inc.php');
  21. $search_query=$_POST['searchQuery'];
  22. $sql = 'SELECT * from bookrecord where MATCH(bookTitle,bookAuthor,bookPublisher) AGAINST(:search_query)';
  23. $statement = $connection->prepare($sql);
  24. $statement->bindParam(':search_query', $search_query, PDO::PARAM_STR);
  25. $statement->execute();
  26. if($statement->rowCount())
  27. {
  28. $row_all = $statement->fetchall(PDO::FETCH_ASSOC);
  29. header('Content-type: application/json');
  30. echo json_encode($row_all);
  31.  
  32. }
  33. elseif(!$statement->rowCount())
  34. {
  35. echo "no rows";
  36. }
  37. }
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement