-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.php
More file actions
83 lines (67 loc) · 1.87 KB
/
Copy pathDatabase.php
File metadata and controls
83 lines (67 loc) · 1.87 KB
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
<?php
/**
* Created by PhpStorm.
* User: Peace Dube
* Date: 2018/06/01
* Time: 07:23 PM
* Description: This is include and code database class for php.
*/
class Database{
private $connection;
public function __construct($sHost, $sUsername, $sPassword, $sDatabase)
{
$rCon = mysqli_connect($sHost, $sUsername, $sPassword,$sDatabase);
// Check connection
if ( !$rCon ) die("Connection failed: " . mysqli_connect_error());
return $this->connection = $rCon;
}
public function query($sSQL = '')
{
$rResult = $this->connection->query($sSQL);
if ($rResult->num_rows > 0)
return new ResultSet($rResult);
else die($this->connection->error);
}
function verify($sUsername, $sPassword)
{
$rResult = $this->query("select id from users where email='$sUsername' and password='$sPassword'");
if ( $rResult->numrows() > 0 ) return $rResult->fetchrow();
else return false;
}
public function is_user($sUsername)
{
$rResult = $this->query("select id from users where email='$sUsername'");
if ($rResult->numrows() > 0) return true;
else return false;
}
}
class ResultSet {
private $iNumRows;
private $iFieldCount;
private $iCurrentField;
private $rResultSet;
function __construct($rResultSet)
{
$this->rResultSet = $rResultSet;
}
public function numrows()
{
return $this->rResultSet->num_rows;
}
public function fieldCount()
{
return $this->rResultSet->field_count;
}
public function currentField()
{
return $this->rResultSet->current_field;
}
public function fetchrow()
{
return $this->rResultSet->fetch_assoc();
}
public function seek($iSeekNum = 0)
{
return $this->rResultSet->data_seek($iSeekNum);
}
}