-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_range.php
executable file
·63 lines (42 loc) · 1.8 KB
/
get_range.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// Check if session is not registered, redirect back to main page.
// Put this code in first line of web page.
session_start();
//table name sent from form
if(isset($_POST['attr'])){
$attr = $_POST['attr'];
}
else {
header("location:connect.php");
}
//$attr = "rowc";
if(!isset($_SESSION["hostname"], $_SESSION["portnum"], $_SESSION["username"], $_SESSION["password"], $_SESSION["dbname"], $_SESSION["tblname"])){
header("location:connect.php");
}
$conn_input = "host={$_SESSION["hostname"]} port={$_SESSION["portnum"]} dbname={$_SESSION["dbname"]} user={$_SESSION["username"]} password={$_SESSION["password"]}";
//$conn_input = "host=dbcluster.cs.umass.edu port=54320 dbname=testdb user=wenzhao password=CSwenCF";
//$dbconn = pg_connect($conn_input) or die('Could not connect: ' . pg_last_error());
$dbconn = pg_connect($conn_input);
if (!$dbconn) {
$message = "Input: host: {$_SESSION["hostname"]}, port: {$_SESSION["portnum"]}, username: {$_SESSION["username"]}, password: {$_SESSION["password"]}, database: {$_SESSION["dbname"]} .\n";
$_SESSION['error_message'] = "Error: Could not connect. " . pg_last_error() . "<br /> {$message} <br />";
header('location:error_page.php');
exit();
}
$query = "select min({$attr}) as min_value, max({$attr}) as max_value from {$_SESSION["tblname"]} where {$attr} > -9999;";
//$result = pg_query($dbconn, $query) or die('Query failed: ' . pg_last_error());
$result = pg_query($dbconn, $query);
if (!$result) {
$_SESSION['error_message'] = "Error: Query failed. " . pg_last_error() . "<br /> {$query} <br />";
header('location:error_page.php');
exit();
}
//$rows = pg_num_rows($result);
$data = array();
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
$data[] = $line;
}
echo json_encode($data);
pg_free_result($result);
pg_close($dbconn);
?>