-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.php
40 lines (34 loc) · 995 Bytes
/
connection.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
<?php
class DBController {
private $host = "localhost";
private $user = "root";
private $password = "";
private $database = "project";
private $conn;
function __construct() {
$this->conn = $this->connectDB();
if(!empty($this->conn)) {
$this->selectDB();
}
}
function connectDB() {
$conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
return $conn;
}
function selectDB() {
mysqli_select_db($this->conn, $this->database);
}
function runQuery($query) {
$result = mysqli_query($this->conn, $query);
while($row=mysqli_fetch_assoc($result)) {
$resultset[] = $row;
}
if(!empty($resultset))
return $resultset;
}
function numRows($query) {
$result = mysqli_query($this->conn, $query);
$rowcount = mysqli_num_rows($result);
return $rowcount;
}
}