Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $connstring = "host=localhost dbname=test user=dwurf password=<secret>";
- $conn = pg_connect($connstring);
- $search = ($_GET['term']);
- if (!$conn) { die('Could not connect: ' . pg_last_error ());}
- else
- {
- $sql = "SELECT name FROM users_table WHERE name ILIKE '%$search%' ORDER BY name ASC";
- $result = pg_query($sql);
- $json = '[';
- $first = true;
- while ($row = pg_fetch_array($result))
- {
- if (!$first) { $json .= ','; } else { $first = false; }
- $json .= '{"value":"'.$row['name'].'"}';
- }
- $json .= ']';
- echo $json;
- exit();
- }
- ?>
Add Comment
Please, Sign In to add comment