-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschool.php
More file actions
23 lines (19 loc) · 720 Bytes
/
Copy pathschool.php
File metadata and controls
23 lines (19 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$pdo = new PDO('mysql:host=localhost; port=3306; dbname=misc', 'kings', 'zap');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
session_start();
if(!isset($_SESSION['user_id'])) {
die('ACCESS DENIED');
return false;
}
header('content-type: application/json; charset=utf-8');
$term = $_GET['term'];
error_log('Looking up typeahead term='.$term);
$sql = "SELECT name FROM institution WHERE name LIKE :prefix";
$stmt = $pdo->prepare($sql);
$stmt->execute(array(':prefix' => $term. "%"));
$retreive = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$retreive[] = $row['name'];
}
echo json_encode($retreive, JSON_PRETTY_PRINT);