infojunkie243

search parameters

Mar 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'localhost';
  4. $db   = 'webcrawler';
  5. $user = 'webcrawler';
  6. $pass = 'secret';
  7. $charset = 'utf8';
  8.  
  9. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  10.  
  11. $pdo = new PDO($dsn, $user, $pass);
  12.  
  13. $sql = 'SELECT * FROM document
  14. WHERE MATCH (`text`, subject, title, description, creator, publisher)
  15. AGAINST (:search IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION);';
  16.  
  17. $stmt = $pdo.prepare($sql);
  18. $stmt.execute(['search' => 'my-search-phrase']);
  19.  
  20. while($doc = $stmt->fetch(PDO::FETCH_OBJ)) {
  21.     echo "URL: $doc->url    Content-Type: $doc->content_type    Crawled Date: $doc->crawl_date";
  22. }
Add Comment
Please, Sign In to add comment