-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDao.php
More file actions
91 lines (66 loc) · 2.18 KB
/
Dao.php
File metadata and controls
91 lines (66 loc) · 2.18 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
84
85
86
87
88
89
90
91
<?php
ini_set('display_erroes',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
class Dao{
private $host= "us-cdbr-iron-east-04.cleardb.net";
private $dbname = "heroku_07605395906fece";
private $user = "bd60ace27042e3";
private $password = "a705e617";
private function getConnection()
{
// Create PDO instance using MySQL connection string.
$conn = new PDO("mysql:dbname={$this->dbname};host={$this->host};", "$this->user", "$this->password");
// Make sure to turn on exceptions for debugging.
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
public function addUser($email, $password, $username)
{
$conn = $this->getConnection();
$digest = $this->hashPassword($password);
$query = "INSERT INTO users (email, password, username) VALUES (:email, :password, :username)";
$stmt = $conn->prepare($query);
$stmt->bindParam(":email", $email);
$stmt->bindParam(":password", $digest);
$stmt->bindParam(":username", $username);
$stmt->execute();
}
public function hashPassword($password)
{
$hash = password_hash($password, PASSWORD_BCRYPT);
return $hash;
}
public function validateUser($email, $password)
{
$conn = $this->getConnection();
$stmt = $conn->prepare("SELECT password FROM users WHERE email= :email");
$stmt->bindParam(':email', $email);
$stmt->execute();
$row = $stmt->fetch();
if(!$row){
return false;
}
$digest = $row['password'];
return password_verify($password, $digest);
}
public function userinfo($email)
{
$conn = $this->getConnection();
$query = "SELECT * FROM users WHERE email = :email";
// Create the prepared statement (returns a PDOStatement object).
$stmt = $conn->prepare($query);
$stmt->bindParam(':email', $email);
// Finally, execute the statement.
$stmt->execute();
// And return the result (an array of rows).
return $stmt->fetch();
}
public function user_learninginfo($email ,$firstlanguage, $learninglanguage){
$conn = $this->getConnection();
$query = "SELECT * FROM users WHERE email = :email";
$query = "INSERT INTO users (email, password, username) VALUES (:email, :password, :username)";
$stmt = $conn->prepare($query);
}
}
?>