blob: fd8d73162a33dc90946ae0e477320d35303fd83c [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
15 function get_users($id = 0) {
16 $users = [];
17
18 // Define MySQL login variables
Andreu09b8b052019-09-21 21:47:20 +020019 $servername = "localhost"; // "andreuhuguet78654.ipagemysql.com";
20 $username = "root"; // "andreu";
21 $password = ""; // "1234";
22 $dbname = "pastanaga"; // "fme_2019";
Andreuabbcb7e2019-09-21 18:22:14 +020023
24 // Create connection
Andreu09b8b052019-09-21 21:47:20 +020025 $conn = new mysqli($servername, $username, $password, $dbname);
Andreuabbcb7e2019-09-21 18:22:14 +020026 if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
27 $conn->set_charset("utf8");
28
29 // Do the query
30 $query = "SELECT * FROM users";
31 if ($id > 0) $query .= " WHERE id=".$id;
32
33 // Fetch the information of the user
34 if ($result = $conn->query($query)) {
35 while ($row = $result->fetch_row()) {
36 $user = new User();
37
38 $user->id = $row[0];
39 $user->nomcomplet = $row[1];
40 $user->curs = $row[2];
41 $user->grau = $row[3];
42 $user->quimata = $row[4];
43 $user->requested = $row[5];
44 $user->mort = $row[6];
45
46 array_push($users, $user);
47 }
48 $result->close();
49 } else {
50 die("Wrong query: " . $query);
51 }
52
53 // Close connection
54 $conn->close();
55
56 if ($id > 0) return $users[0];
57 else return $users;
58 }
59?>