-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-companies.php
More file actions
29 lines (28 loc) · 859 Bytes
/
api-companies.php
File metadata and controls
29 lines (28 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
require_once 'config.php';
require_once 'db-classes.php';
// Tell the browser to expect JSON rather than HTML
header('Content-type: application/json');
// indicate whether other domains can use this API
header("Access-Control-Allow-Origin: *");
try {
$conn = DatabaseHelper::createConnection(array(DBCONNSTRING, DBUSER, DBPASS));
$gateway = new CompanyDB($conn);
if ( isCorrectQueryStringInfo("symbol") )
$companies = $gateway->getAllForSymbol($_GET["symbol"]);
else
$companies = $gateway->getAll();
echo json_encode( $companies, JSON_NUMERIC_CHECK+JSON_PRETTY_PRINT );
}
catch (Exception $e) {
die( $e->getMessage() );
}
function isCorrectQueryStringInfo($param) {
if ( isset($_GET[$param]) && !empty($_GET[$param]) ) {
return true;
}
else {
return false;
}
}
?>