blob: 084c41c4ff6eb6960143585c02cd1d18375fc16e [file] [log] [blame]
Andreuabbcb7e2019-09-21 18:22:14 +02001<?php
2 class User{
3 public $id;
4 public $nomcomplet;
5 public $curs;
6 public $grau;
7 public $quimata;
8
9 public function nom() {
10 $noms = explode(" ", $this->nomcomplet);
11 return $noms[0];
12 }
13 }
14
Andreu20cbd1d2019-09-22 00:00:57 +020015 function query($query) {
Andreuabbcb7e2019-09-21 18:22:14 +020016 // Define MySQL login variables
Andreu09b8b052019-09-21 21:47:20 +020017 $servername = "localhost"; // "andreuhuguet78654.ipagemysql.com";
18 $username = "root"; // "andreu";
19 $password = ""; // "1234";
20 $dbname = "pastanaga"; // "fme_2019";
Andreuabbcb7e2019-09-21 18:22:14 +020021
22 // Create connection
Andreu09b8b052019-09-21 21:47:20 +020023 $conn = new mysqli($servername, $username, $password, $dbname);
Andreuabbcb7e2019-09-21 18:22:14 +020024 if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
25 $conn->set_charset("utf8");
26
Andreu20cbd1d2019-09-22 00:00:57 +020027 // Execute query and save result
28 $result = $conn->query($query);
29
30 // Close the connection
31 $conn->close();
32
33 // Return result of query
34 return $result;
35 }
36
37 function get_users($id = 0) {
38 $users = [];
39
40 // Prepare the query
Andreuabbcb7e2019-09-21 18:22:14 +020041 $query = "SELECT * FROM users";
42 if ($id > 0) $query .= " WHERE id=".$id;
43
44 // Fetch the information of the user
Andreu20cbd1d2019-09-22 00:00:57 +020045 if ($result = query($query)) {
Andreuabbcb7e2019-09-21 18:22:14 +020046 while ($row = $result->fetch_row()) {
47 $user = new User();
48
49 $user->id = $row[0];
50 $user->nomcomplet = $row[1];
51 $user->curs = $row[2];
52 $user->grau = $row[3];
53 $user->quimata = $row[4];
54 $user->requested = $row[5];
55 $user->mort = $row[6];
Andreu20cbd1d2019-09-22 00:00:57 +020056 $user->md5password = $row[7];
Andreuabbcb7e2019-09-21 18:22:14 +020057
58 array_push($users, $user);
59 }
60 $result->close();
61 } else {
62 die("Wrong query: " . $query);
63 }
Andreuabbcb7e2019-09-21 18:22:14 +020064
65 if ($id > 0) return $users[0];
66 else return $users;
67 }
68?>