-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAL.php
44 lines (33 loc) · 894 Bytes
/
DAL.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
<?php
class DAL{
public function __construct(\mysqli $db) {
$this->database = $db;
}
public $mysqli;
// public function connectToDB(){
// $this->mysqli = new mysqli("104.131.98.91", "root", "GrovSnus2", "php4");
// if (mysqli_connect_errno()) {
// printf("Connect failed: %s\n", mysqli_connect_error());
// exit();
// }
// else{
// echo "conected";
// }
public function addToDB(User $toBeAdded){
$usrName = $toBeAdded->getUserName();
$password = $toBeAdded->getPassword();
try{
$var = null;
$stmt = $this->database->prepare("INSERT INTO `php4`.`Users` (`id`, `name`, `password`) VALUES (?, ?, ?)");
//var_dump($stmt);
if ($stmt === FALSE) {
echo "kuken";
}
$stmt->bind_param('iss',$var, $usrName ,$password );
$stmt->execute();
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}