-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbconnect.php
More file actions
33 lines (33 loc) · 856 Bytes
/
dbconnect.php
File metadata and controls
33 lines (33 loc) · 856 Bytes
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
<?php
class dbClass
{
private $connection;
function __construct()
{
$this->mysqlConnect('localhost', 'root', '', 'teacher_evaluation');
}
private function mysqlConnect($host, $username, $password, $name)
{
$this->connection = new mysqli($host, $username, $password, $name);
if ($this->connection->connect_error) {
die("Connection failed: " . $this->connection->connect_error);
}
}
public function getConnection()
{
return $this->connection;
}
function myQuery($query)
{
$result = $this->connection->query($query);
if (!$result) {
die("Query failed: " . $this->connection->error);
}
$data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
return $data;
}
}
?>