-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
56 lines (50 loc) · 1.46 KB
/
db.php
File metadata and controls
56 lines (50 loc) · 1.46 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
49
50
51
52
53
54
55
56
<?php
//If you enable that your page can be slower and your data usage get's very high.
//Disable = false
//Enable = true
const REFRESH = false;
//Every 10 seconds
const time = 10;
class DB
{
//Set the host in most cases it is the localhost
private $db_host = "localhost";
//Set the user
private $db_user = "Tasks";
//Set the database name of the system
private $db_db = "Tasks";
//Set the password of the user
private $db_pws = "Tasks";
public $conn;
function close()
{
$this->conn = null;
}
function __destruct()
{
$this->conn = null;
}
function __construct()
{
try {
$hostname = $this->db_host;
$DB = $this->db_db;
$username = $this->db_user;
$password = $this->db_pws;
if ($DB == "" || $username == "") {
echo "Setup error! Set the values";
exit();
}
$this->conn = new PDO("mysql:host=$hostname;dbname=$DB", $username, $password);
// set the PDO error mode to exception
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
//echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
exit();
}
}
}
?>
<p></p>