-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.php
71 lines (62 loc) · 2.88 KB
/
validate.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
64
65
66
67
68
69
70
71
<?php
$DSN_CONFIG_FILE = 'config/Database.ini';
$databaseConfig = parse_ini_file($DSN_CONFIG_FILE);
if (! file_exists($DSN_CONFIG_FILE)) {
throw new RuntimeException('Database config file not found: ' . $DSN_CONFIG_FILE);
}
$databaseConfig = parse_ini_file($DSN_CONFIG_FILE);
if (! isset($databaseConfig['dsn'])) {
throw new RuntimeException("Database config parameter 'dsn' not found in config file: " . $DSN_CONFIG_FILE);
}
$username = null;
$password = null;
if (preg_match('/^(mysql|pgsql)/', $databaseConfig['dsn'], $matches)) {
$driver = $matches[1];
if (! isset($databaseConfig['username'])) {
throw new RuntimeException("Database config parameter 'username' not found in config file: " . $DSN_CONFIG_FILE);
}
if (! isset($databaseConfig['password'])) {
throw new RuntimeException("Database config parameter 'password' not found in config file: " . $DSN_CONFIG_FILE);
}
$username = $databaseConfig['username'];
$password = $databaseConfig['password'];
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
} else {
if (! isset($databaseConfig['filename'])) {
throw new RuntimeException("Database config parameter 'filename' not found in config file: " . $DSN_CONFIG_FILE);
}
if (! is_writable(dirname($databaseConfig['filename']))) {
throw new RuntimeException('Data directory not writable by web server: ' . dirname($databaseConfig['filename']) . '/');
}
if (! is_writable(dirname($databaseConfig['filename'])) || (file_exists($databaseConfig['filename']) && ! is_writable($databaseConfig['filename']))) {
throw new RuntimeException('Database file not writable by web server: ' . $databaseConfig['filename']);
}
}
try {
$pdo = new PDO($databaseConfig['dsn'], $username, $password,$options);
if ($driver == 'sqlite') {
$pdo->exec('PRAGMA foreign_keys = ON;');
}
} catch (PDOException $e) {
throw new PDOException('PDOException: ' . $e->getMessage());
}
if (isset($_GET['input_survey_name'])) {
$new_survey_name = strtolower($_GET['input_survey_name']);
$params = ['survey_name' => $new_survey_name];
}
else {
print "err: no survey name given";
}
$sql = "select survey_name from survey where lower(survey_name) = :survey_name";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$results = $stmt->fetchColumn();
if ($results) { //Found
print "true";
}
else {
print "false";
}
?>