-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgetDB.php
More file actions
executable file
·48 lines (43 loc) · 1.54 KB
/
getDB.php
File metadata and controls
executable file
·48 lines (43 loc) · 1.54 KB
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
<?php
function getDatabaseHandle() {
if(isset($_REQUEST['dbName'])){
$dbName = $_REQUEST['dbName'];
}
if(isset($dbName)){
if($dbName == "retainer.db") {
$dbh = new PDO('sqlite:' . dirname(__FILE__) . '/db/retainer.db');
}
else{
$hash1 = $_REQUEST['dbName'];
$tableName = $hash1;
//$tableName = hash("sha256", $hash1);
// echo $tableName;
$dbh = new PDO('sqlite:' . dirname(__FILE__) . '/db' .'/' . $tableName . '.db');
}
}
//else if($_REQUEST['accessKey'] == "use_file" && $_REQUEST['secretKey'] == "use_file"){
// //The database with tables for the retainer tool
// $dbh = new PDO('sqlite:' . dirname(__FILE__) . '/db/retainer.db');
//}
else{
$accessKey = $_REQUEST['accessKey'];
$secretKey = $_REQUEST['secretKey'];
$hash1 = hash("sha256", $accessKey) . hash("sha256", $secretKey);
$tableName = hash("sha256", $hash1);
//The database with tables for the retainer tool
$dbh = new PDO('sqlite:' . dirname(__FILE__) . '/db' .'/' . $tableName . '.db');
}
// $file = 'nums.txt';
// // Open the file to get existing content
// $current = file_get_contents($file);
// // Append a new person to the file
// $current .= "Access key: " . $accessKey . "\n";
// $current .= "Secret key: " . $secretKey . "\n";
// $current .= "tableName: " . $tableName . "\n";
// // Write the contents back to the file
// file_put_contents($file, $current);
// $dbh->setAttribute(PDO::ATTR_TIMEOUT, 10);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
?>