Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Action on MYSQL
- */
- class dotabase
- {
- public $connect;
- public function __construct()
- {
- $this->connect=mysqli_connect('localhost','root','','sakteh');
- return $this->connect;
- }
- public function query($sql)
- {
- $conn=$this->connect;
- $query=mysqli_query($conn,$sql);
- return $query;
- }
- public function read($table,$argument="")
- {
- $sql="SELECT * FROM $table ".$argument;
- return $this->query($sql);
- }
- public function create($table,$colomn,$value)
- {
- $sql="INSERT INTO $table(".$colomn.") VALUES (".$value.")";
- echo $sql;
- }
- public function update($table,$id,$update)
- {
- $sql="UPDATE ".$table." SET (".$update.") WHERE id=$id";
- echo $sql;
- }
- public function delete($table,$id)
- {
- $sql="DELETE FROM $table WHERE id=$id";
- echo $sql;
- }
- public function search($table,$colomn,$value)
- {
- $sql="SELECT * FROM $table WHERE $colomn LIKE %$value%";
- echo $sql;
- }
- public function fetch()
- {
- return mysqli_fetch_assoc($this->sql);
- }
- public function read($table,$argument="")
- {
- $sql="SELECT * FROM $table ".$argument;
- return $this->query($sql);
- }
- public function escape($string)
- {
- return mysqli_real_escape_string($string);
- }
- }
- /**
- * Admin
- */
- class admin extends dotabase
- {
- public function userAll()
- {
- $this->read("user");
- return $this;
- }
- public function userDel($userID)
- {
- $this->delete("user",$userID);
- return $this;
- }
- public function userUpdate($userID,$username,$password)
- {
- $this->update("user",$userID,"username='$username',password='$password'");
- return $this;
- }
- public function userAdd($username,$password,$full)
- {
- $this->create("user","username,password,fullname","'$username','$password','$full' ");
- return $this;
- }
- public function userID($id)
- {
- $this->sql=$this->read("user","id=$id");
- return $this;
- }
- }
- /**
- * There is an Client
- */
- class Clients extends dotabase
- {
- public function CreateItem($name,$price,$image,$description)
- {
- $this->create("product","nama,harga,img,deskripsi","'$name','$price','$image','$description' ");
- return $this;
- }
- public function UpdateItem($id,$name,$price,$image,$descr)
- {
- $this->update("product",$id,"nama='$name',harga='$price',deskripsi='$descr',img='$image'");
- return $this;
- }
- public function Register($user,$pass,$full)
- {
- $this->create("user","username,password,fullname","'$user','$pass','$full' ");
- return $this;
- }
- public function DelMyAccount($id)
- {
- $this->delete("user",$id);
- return $this;
- }
- }
- // Disini Aksi Database
- $a=new dotabase;
- // $a->search("nona","nama","merry");
- // echo "<br>";
- // $a->read("nona","WHERE status='lajang'");
- // echo "<br>";
- // $a->create("nona","gadis","shiro");
- // echo "<br>";
- // $a->update("nona","2","status","lajang");
- // echo "<br>";
- // $a->delete('nona',"2");
- // echo "<br>";
- // Disini Aksi Client
- $b=new Clients;
- // $b->CreateItem('Kolak','5000','kolaj.jpg','This is Drink From Indonesian');
- // echo "<br>";
- // $b->UpdateItem(2,"Kolak Pisang","5000","kolak.jpg","Indonesia Punya Bro/Sist");
- // echo "<br>";
- // Disini Aksi Admin
- $c=new admin;
- // $c->userUpdate(2,"Bakhti","root");
- // echo "<br>";
- // $c->userDel(2);
- // echo "<br>";
- // $c->userAdd("Bakhti","root");
- // echo "<br>";
- // $c->userID(1);
- // echo "<br>";
- while ($fetch=$c->userAll()->fetch()) {
- echo $fetch['fullname'];
- }
- // Maaf Masih Belajar
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement