-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
86 lines (83 loc) · 1.8 KB
/
database.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
//header to include the page named "config.php"
include "config.php";
?>
<?php
Class Database
{
public $host = DB_HOST;
public $user = DB_USER;
public $pass = DB_PASS;
public $dbname = DB_NAME;
public $link;
public $error;
//constructor
public function __construct()
{
$this->connection();
}
private function connection()
{
$this->link = new mysqli($this->host,$this->user,$this->pass,$this->dbname);
//to show if there is any problem in the connection
if(!$this->link)
{
$this->error = "Connection failed".$this->link->connect_error;
return false;
}
}
//Select or Read
public function select($query)
{
$result = $this->link->query($query) or die ($this->link->error.__LINE__);
//for checking if the data row is blank
if($result-> num_rows > 0)
{
return $result;
}
else
{
return false;
}
}
//function which will be called for inserting data
public function insert($query)
{
$insert_row = $this->link->query($query) or die ($this->link->error.__LINE__);
if($insert_row)
{
//header("Location: select.php?msg=".urlencode('Data inserted succesfully.'));
echo "You have registered succesfully!!!";
exit();
}
else
{
die("Error:(".$this->link->errno.")".$this->link->error);
}
}
public function search($query)
{
$result = $this->link->query($query) or die ($this->link->error.__LINE__);
if($result-> num_rows == 1)
{
return $result;
}
else
{
return false;
}
}
public function login($query)
{
$result = $this->link->query($query) or die ($this->link->error.__LINE__);
if($result-> num_rows == 1)
{
return $result;
}
else
{
return false;
}
}
}
?>