-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-connect.php
55 lines (39 loc) · 1.37 KB
/
db-connect.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
<?php
require_once('authenticate.php');
class dbConnect{
private $mysqli;
private $quiet;
public function query($query) {
$result = $this->mysqli->query($query);
if (! $result) {
die( ($this->quiet !== TRUE ? "Oops... Error in a query string. <br>Server says: " . $this->mysqli->error . ".<br>Couldn't proceed. Script terminated." : ""));
}
else {
if ($this->quiet !== TRUE) echo ((strlen($query) > 20) ? substr($query,0,25).'... ' : $query) .'ok. ' . ($this->mysqli->info ? $this->mysqli->info . ".<br>" : "<br>");
}
return $result;
}
public function sanitize($input) {
if ($input == NULL || $input == 'undefined') return NULL;
return $this->mysqli->real_escape_string($input);
}
public function __construct($db, $info=FALSE, $quiet=TRUE) {
$this->quiet = $quiet;
$this->mysqli = new mysqli(
$db['host'],
$db['user'],
$db['pass'],
($info === FALSE ? $db['dbname'] : 'information_schema')
);
if (mysqli_connect_error()) {
die( ($this->quiet !== TRUE ? 'Error in connecting to database. <br>Server says: Error ' . mysqli_connect_errno() . '. ' . mysqli_connect_error() . ".<br>Script terminated.": '') );
}
else{
if ($this->quiet !== TRUE) echo 'Connected to database. ' . $this->mysqli->host_info . ".<br>";
}
}
public function __destruct() {
$this->mysqli->close();
}
}
?>