-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
54 lines (42 loc) · 1.79 KB
/
functions.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
<?php
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'crud_oop');
class DB_con {
function __construct() {
$conn = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
$this->dbcon = $conn;
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL : " . mysqli_connect_error();
}
}
public function insert($firstname, $lastname, $email, $phonenumber, $address) {
$result = mysqli_query($this->dbcon, "INSERT INTO tblusers(firstname, lastname, email, phonenumber, address) VALUES('$firstname', '$lastname', '$email', '$phonenumber', '$address')");
return $result;
}
public function fetchdata() {
$result = mysqli_query($this->dbcon, "SELECT * FROM tblusers");
return $result;
}
public function fetchonerecord($userid) {
$result = mysqli_query($this->dbcon, "SELECT * FROM tblusers WHERE id = '$userid'");
return $result;
}
public function update($firstname, $lastname, $email, $phonenumber, $address, $userid) {
$result = mysqli_query($this->dbcon, "UPDATE tblusers SET
firstname = '$firstname',
lastname = '$lastname',
email = '$email',
phonenumber = '$phonenumber',
address = '$address'
WHERE id = '$userid'
");
return $result;
}
public function delete($userid) {
$deleterecord = mysqli_query($this->dbcon, "DELETE FROM tblusers WHERE id = '$userid'");
return $deleterecord;
}
}
?>