-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.php
59 lines (50 loc) · 1.51 KB
/
connection.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
<?php
class Connection {
private $dbhost = null;
private $dbuser = null;
private $dbpass = null;
private $db = null;
private $conn;
public function __construct()
{
$this->dbhost = 'localhost';
$this->dbuser = 'root';
$this->dbpass = '1234';
$this->db = 'app_mobile_course';
}
private function OpenCon()
{
$this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->db) or die("Connect failed: %s\n". $conn -> error);
return true;
}
public function authenticate( $username, $password ) {
$this->OpenCon();
$sqlQuery = "SELECT name FROM user WHERE username = ? AND password = ? LIMIT 1";
$response = false;
/* crear una sentencia preparada */
if ($stmt = $this->conn->prepare($sqlQuery)) {
/* ligar parámetros para marcadores */
$stmt->bind_param('ss', $username, $password);
/* ejecutar la consulta */
$stmt->execute();
/* obtener valor */
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ( $row != false ) {
$response = [
'name' => $row['name']
];
/* cerrar sentencia */
$stmt->close();
}
}
/* cerrar conexión */
$this->CloseCon();
return $response;
}
public function CloseCon()
{
$this->conn->close();
}
}
?>