
<?php

//server credentials
$host = "db.soic.indiana.edu";
$user = "caps15_team3";
$pass = "my+sql=caps15_team3";
$dbname = "caps15_team3";

$dsn = "mysql:host={$host};dbname={$dbname}";
$pdo = new PDO($dsn, $user, $pass);

$returnValue = array();

$query = htmlentities($_POST["query"]);

$search = "%$query%";
$sql = ("SELECT beer_name FROM beer WHERE beer_name LIKE '" .$search. "'");

$statement = $pdo->prepare($sql);
$statement->execute();

$array = $statement->fetchALL(PDO::FETCH_NUM);
unset($statement);

//for ($i = 0; $i < sizeof($array); $i++){ 
//}


foreach ($array as $value){
  $value = array("name" => $value[0]);
  array_push($returnValue, $value);
}


echo json_encode($returnValue);


?>