-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySQL.inc.php
55 lines (48 loc) · 1.29 KB
/
MySQL.inc.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
/************************************************
* Module: MySQL.inc.php *
* Author Name: J.D. Stone *
* *
* Purpose: Database interaction helper methods *
*************************************************/
class MySQL {
// Declare variables
public $dblink;
public $db_username;
public $db_password;
public $db_name;
public function __construct() {
// "In Main (BaseClass) constructor"
$this->db_name = "";
$this->db_username = "";
$this->db_password = "";
}
// 'set' Methods
function setDatabase($db) {
$this->db_name = $db;
}
function setDbUsername($dbUsername) {
$this->db_username = $dbUsername;
}
function setDbPassword($dbPassword) {
$this->db_password = $dbPassword;
}
// MySQL database connection function
public function dbConnect() {
$this->dblink = new mysqli('localhost', $this->db_username, $this->db_password, $this->db_name);
if ($this->dblink->connect_error) {
die('Connect Error ('.$this->dblink->connect_errno.')'
.$this->dblink->connect_error);
}
}
// MySQL database query function
public function doQuery($query) {
$result = $this->dblink->query($query, MYSQLI_STORE_RESULT);
if ($this->dblink->error) {
die('Query Error ('.$this->dblink->errno.')'
.$this->dblink->error);
}
return $result;
}
}
?>