Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $servername = "mysql8.000webhost.com";
- $username = "removed";
- $password = "removed";
- $dbname = "removed";//I removed them cause, you know security matters hahaha
- try {
- $connection = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- die("OOPs something went wrong");
- }
- <?php
- if(isset($_POST['searchQuery']))
- {
- require_once('config.inc.php');
- $search_query=$_POST['searchQuery'];
- $sql = 'SELECT * from bookrecord where MATCH(bookTitle,bookAuthor,bookPublisher) AGAINST(:search_query)';
- $statement = $connection->prepare($sql);
- $statement->bindParam(':search_query', $search_query, PDO::PARAM_STR);
- $statement->execute();
- if($statement->rowCount())
- {
- $row_all = $statement->fetchall(PDO::FETCH_ASSOC);
- header('Content-type: application/json');
- echo json_encode($row_all);
- }
- elseif(!$statement->rowCount())
- {
- echo "no rows";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement