Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. <?php
  2. include("../config.php");
  3. class db
  4. {
  5.     public $host;
  6.     public $user;
  7.     public $pass;
  8.     public $data;
  9.     public $conn;
  10.     public $table;
  11.     function db()
  12.     {
  13.         global $servername, $dbusername, $dbpassword, $dbname;
  14.         $this->host=$servername;
  15.         $this->user=$dbusername;
  16.         $this->pass=$dbpassword;
  17.         $this->data=$dbname;
  18.         $this->conn=new mysqli($this->host, $this->user, $this->pass, $this->data);
  19.     }
  20.     public function connect()
  21.     {
  22.         if(!$this->conn)
  23.         {
  24.             return mysqli_error();
  25.         }
  26.         $sel=mysqli_select_db($this->conn, $this->data);
  27.         if(!$sel)
  28.         {
  29.             return mysqli_error();
  30.         }
  31.     }
  32.     public function insertCategory($name)
  33.     {
  34.         $query=mysqli_query($this->conn, "INSERT INTO categories(name) VALUES('$name')");
  35.  
  36.         if ($query) {
  37.             return "Rij is succesvol toegevoegd.";
  38.         } else {
  39.             return "Error: " . mysqli_error($this->conn);
  40.         }
  41.     }
  42.     public function updateCategory($id, $name)
  43.     {
  44.         $query=mysqli_query($this->conn, "UPDATE categories SET name='$name' WHERE id='$id'");
  45.  
  46.         if ($query) {
  47.             return "Rij is succesvol veranderd.";
  48.         } else {
  49.             return "Error: " . mysqli_error($this->conn);
  50.         }
  51.     }
  52.     public function deleteCategory($id)
  53.     {
  54.         $query=mysqli_query($this->conn, "DELETE FROM categories WHERE id='$id'");
  55.  
  56.         if ($query) {
  57.             return "Rij is succesvol verwijderd.";
  58.         } else {
  59.             return "Error: " . mysqli_error($this->conn);
  60.         }
  61.     }
  62. }
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement