Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class dbclass{
- private $db;
- function __construct(){
- try{
- $this->db = new PDO('mysql::host=localhost;dbname=SIZADANIE;port=3306', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
- }catch(PDOException $e){
- echo "Błąd ". $e->getMessage();
- }
- }
- function pobierzUrzytkownikow(){
- $stmt = $this->db->query("SELECT id, imie, nazwisko, login FROM user");
- return $stmt->fetchAll();
- }
- function dodajUrzytkownika($imie, $nazwisko, $login, $pass){
- $stmt = $this->db->prepare("INSERT INTO user(imie,nazwisko,login,pass) VALUES(:imie, :nazwisko, :login, :pass)");
- $stmt->bindValue(":imie", $imie, PDO::PARAM_STR);
- $stmt->bindValue(":nazwisko", $nazwisko, PDO::PARAM_STR);
- $stmt->bindValue(":login", $login, PDO::PARAM_STR);
- $stmt->bindValue(":pass", $pass, PDO::PARAM_STR);
- return $stmt->execute();
- }
- function odswierzUrzytkownika($id, $imie, $nazwisko, $login, $pass){
- $stmt = $this->db->prepare("UPDATE user SET imie=:imie, nazwisko=:nazwisko, login=:login, pass=:pass WHERE id=:id");
- $stmt->bindValue(":imie", $imie, PDO::PARAM_STR);
- $stmt->bindValue(":nazwisko", $nazwisko, PDO::PARAM_STR);
- $stmt->bindValue(":login", $login, PDO::PARAM_STR);
- $stmt->bindValue(":pass", $pass, PDO::PARAM_STR);
- $stmt->bindValue(":id", $id, PDO::PARAM_INT);
- return $stmt->execute();
- }
- function usunUrzytkownika($id){
- $stmt = $this->db->prepare("DELETE FROM user WHERE id = :id");
- $stmt->bindValue(":id", $id, PDO::PARAM_INT);
- return $stmt->execute();
- }
- function urzytkownik_z_id($id){
- $stmt = $this->db->prepare("SELECT * FROM user WHERE id = :id");
- $stmt->bindValue(":id", $id, PDO::PARAM_INT);
- $stmt->execute();
- return $stmt->fetchAll();
- }
- function pobierzDostepneKsiazki(){
- $stmt = $this->db->query("SELECT b.id, b.title, b.author FROM book b LEFT JOIN pozyczone p ON b.id = p.book_id WHERE p.user_id IS NULL");
- return $stmt->fetchAll();
- }
- function wyporzyczKsiazke($bookid, $userid){
- $stmt = $this->db->prepare("INSERT INTO pozyczone(book_id, user_id) VALUES(:b, :u)");
- $stmt->bindValue(":b", $bookid, PDO::PARAM_INT);
- $stmt->bindValue(":u", $userid, PDO::PARAM_INT);
- return $stmt->execute();
- }
- function pobierzWyporzyczoneKsiazki($userid){
- $stmt = $this->db->prepare("SELECT b.id, b.title, b.author FROM book b INNER JOIN pozyczone p ON b.id = p.book_id WHERE p.user_id = :u");
- $stmt->bindValue(":u", $userid, PDO::PARAM_INT);
- $stmt->execute();
- return $stmt->fetchAll();
- }
- function oddajKsiazke($bookid){
- $stmt = $this->db->prepare("DELETE FROM pozyczone WHERE book_id = :b");
- $stmt->bindValue(":b", $bookid, PDO::PARAM_INT);
- return $stmt->execute();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement