Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Baza {
- private $mysqli;
- public function __construct($serwer, $user, $pass, $baza) {
- $this->mysqli = new mysqli($serwer, $user, $pass, $baza);
- if ($this->mysqli->connect_errno) {
- printf("Nie udało się połączyć z serwerem: %s\n", $this->mysqli->connect_error);
- exit();
- }
- $this->mysqli->set_charset("utf8");
- }
- function __destruct() {
- $this->mysqli->close();
- }
- public function select($sql, $pola) {
- $tresc = "";
- if ($result = $this->mysqli->query($sql)) {
- $ilepol = count($pola);
- $tresc .= "<table><tbody>";
- $ktory = 1;
- while ($row = $result->fetch_object()) {
- $tresc .= "<tr>";
- for ($i = 0; $i < $ilepol - 1; $i++) {
- $p = $pola[$i];
- $tresc .= "<td>" . $row->$p . "  </td>";
- if ($i == 2) {
- $p = $pola[$i + 1];
- $tresc .= "<td>Średnia ocen: " . $row->$p . "%</td>" . "<td> <form action=\"formularz.php\" method=\"post\" ><input type=\"submit\" value=\"" . $ktory . "\" name=\"submit\" ><input type=\"submit\" value=\"" . ($ktory * -1) . "\" name=\"submit\" ></form></td>";
- $ktory++;
- }
- }
- }
- $tresc .= "</tr>";
- }
- $tresc .= "</table>";
- return $tresc;
- }
- public function insert($sql) {
- $ret = true;
- if ($stmt = $this->mysqli->prepare($sql)) {
- $stmt->execute();
- } else {
- $ret = false;
- }
- return $ret;
- }
- public function zmienOcenePlus($wiersz) {
- insert("UPDATE papryka p1 SET p1.good_rev = p1.good_rev +1 WHERE p1.id =( SELECT p2.id FROM (SELECT * FROM papryka) p2 LIMIT 1 OFFSET $wiersz )");
- }
- public function zmienOceneMinus($wiersz) {
- insert("UPDATE papryka p1 SET p1.bad_rev = p1.bad_rev +1 WHERE p1.id =( SELECT p2.id FROM (SELECT * FROM papryka) p2 LIMIT 1 OFFSET $wiersz )");
- }
- public function selectUser($login, $passwd, $tabela) {
- //parametry $login, $passwd , $tabela – nazwa tabeli z użytkownikami
- //wynik – id użytkownika lub -1 jeśli dane logowania nie są poprawne
- $id = -1;
- $sql = "SELECT * FROM $tabela WHERE userName='$login'";
- if ($result = $this->mysqli->query($sql)) {
- $ile = $result->num_rows;
- if ($ile == 1) {
- $row = $result->fetch_object(); //pobierz rekord z użytkownikiem
- $hash = $row->passwd; //pobierz zahaszowane hasło użytkownika
- //sprawdź czy pobrane hasło pasuje do tego z tabeli bazy danych:
- if (password_verify($passwd, $hash))
- $id = $row->id; //jeśli hasła się zgadzają - pobierz id użytkownika
- }
- }
- return $id; //id zalogowanego użytkownika(>0) lub -1
- }
- public function getId() {
- //parametry $login, $passwd , $tabela – nazwa tabeli z użytkownikami
- //wynik – id użytkownika lub -1 jeśli dane logowania nie są poprawne
- $id = -1;
- $sql = "SELECT * FROM logged_in_users limit 1";
- if ($result = $this->mysqli->query($sql)) {
- $ile = $result->num_rows;
- if ($ile == 1) {
- $row = $result->fetch_object(); //pobierz rekord z użytkownikiem
- $id = $row->userId; //pobierz zahaszowane hasło użytkownika
- }
- }
- return $id; //id zalogowanego użytkownika(>0) lub -1
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement