$dbhost = 'localhost'; $dbuser = '******'; $dbpass = '******'; $dbname = 'changeIt'; $dbmethod = 'mysql:dbname='; $dsn = $dbmethod . $dbname; $pdo = new PDO($dsn, $dbuser, $dbpass); $db = new NotORM($pdo); // route $app->get('/', function () { echo 'Home Page'; }); // all citations $app->get('/citation', function () use($app, $db) { $citations = array(); foreach ($db->ps_citations() as $citation) { $citations[] = array('citation' => $citation['citation'], 'plate' => $citation['plate'], 'state' => $citation['state'], 'fine' => $citation['fine'], 'date' => $citation['date'], 'violation' => $citation['violation'], 'description' => $citation['description'], 'flags' => $citation['flags']); } $app->response()->header("Content-Type", "application/json"); echo json_encode($citations, JSON_FORCE_OBJECT); }); //Single citation $app->get('/citation/:citation', function ($citationPick) use($app, $db) { $app->response()->header("Content-Type", "application/json"); $citation = $db->ps_citations()->where('citation', $citationPick); if ($data = $citation->fetch()) { echo json_encode(array('citation' => $data['citation'], 'plate' => $data['plate'], 'state' => $data['state'], 'fine' => $data['fine'], 'date' => $data['date'], 'violation' => $data['violation'], 'description' => $data['description'], 'flags' => $data['flags'])); } else { echo json_encode(array('status' => false, 'message' => "Citation ID {$citationPick} does not exist")); } });