Guest User

Untitled

a guest
Oct 5th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. $connstring = "host=localhost dbname=test user=dwurf password=<secret>";
  3. $conn = pg_connect($connstring);
  4.  
  5. $search = ($_GET['term']);
  6. if (!$conn) { die('Could not connect: ' . pg_last_error ());}
  7. else
  8. {
  9.  
  10. $sql = "SELECT name FROM users_table WHERE name ILIKE '%$search%' ORDER BY name ASC";
  11. $result = pg_query($sql);
  12. $json = '[';
  13. $first = true;
  14. while ($row = pg_fetch_array($result))
  15. {
  16.  
  17. if (!$first) { $json .= ','; } else { $first = false; }
  18. $json .= '{"value":"'.$row['name'].'"}';
  19. }
  20. $json .= ']';
  21. echo $json;
  22.  
  23. exit();
  24.  
  25. }
  26. ?>
Add Comment
Please, Sign In to add comment