Advertisement
Bakhti31

Untitled

Apr 17th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Action on MYSQL
  5. */
  6. class dotabase
  7. {
  8. public $connect;
  9. public function __construct()
  10. {
  11. $this->connect=mysqli_connect('localhost','root','','sakteh');
  12. return $this->connect;
  13. }
  14. public function query($sql)
  15. {
  16. $conn=$this->connect;
  17. $query=mysqli_query($conn,$sql);
  18. return $query;
  19. }
  20. public function read($table,$argument="")
  21. {
  22. $sql="SELECT * FROM $table ".$argument;
  23. return $this->query($sql);
  24. }
  25. public function create($table,$colomn,$value)
  26. {
  27. $sql="INSERT INTO $table(".$colomn.") VALUES (".$value.")";
  28. echo $sql;
  29. }
  30. public function update($table,$id,$update)
  31. {
  32. $sql="UPDATE ".$table." SET (".$update.") WHERE id=$id";
  33. echo $sql;
  34. }
  35. public function delete($table,$id)
  36. {
  37. $sql="DELETE FROM $table WHERE id=$id";
  38. echo $sql;
  39. }
  40. public function search($table,$colomn,$value)
  41. {
  42. $sql="SELECT * FROM $table WHERE $colomn LIKE %$value%";
  43. echo $sql;
  44. }
  45. public function fetch()
  46. {
  47. return mysqli_fetch_assoc($this->sql);
  48. }
  49. public function read($table,$argument="")
  50. {
  51. $sql="SELECT * FROM $table ".$argument;
  52. return $this->query($sql);
  53. }
  54. public function escape($string)
  55. {
  56. return mysqli_real_escape_string($string);
  57. }
  58. }
  59.  
  60.  
  61.  
  62. /**
  63. * Admin
  64. */
  65. class admin extends dotabase
  66. {
  67. public function userAll()
  68. {
  69. $this->read("user");
  70. return $this;
  71. }
  72. public function userDel($userID)
  73. {
  74. $this->delete("user",$userID);
  75. return $this;
  76. }
  77. public function userUpdate($userID,$username,$password)
  78. {
  79. $this->update("user",$userID,"username='$username',password='$password'");
  80. return $this;
  81. }
  82. public function userAdd($username,$password,$full)
  83. {
  84. $this->create("user","username,password,fullname","'$username','$password','$full' ");
  85. return $this;
  86. }
  87. public function userID($id)
  88. {
  89. $this->sql=$this->read("user","id=$id");
  90. return $this;
  91. }
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /**
  101. * There is an Client
  102. */
  103. class Clients extends dotabase
  104. {
  105. public function CreateItem($name,$price,$image,$description)
  106. {
  107. $this->create("product","nama,harga,img,deskripsi","'$name','$price','$image','$description' ");
  108. return $this;
  109. }
  110. public function UpdateItem($id,$name,$price,$image,$descr)
  111. {
  112. $this->update("product",$id,"nama='$name',harga='$price',deskripsi='$descr',img='$image'");
  113. return $this;
  114. }
  115. public function Register($user,$pass,$full)
  116. {
  117. $this->create("user","username,password,fullname","'$user','$pass','$full' ");
  118. return $this;
  119. }
  120. public function DelMyAccount($id)
  121. {
  122. $this->delete("user",$id);
  123. return $this;
  124. }
  125. }
  126.  
  127.  
  128.  
  129.  
  130. // Disini Aksi Database
  131.  
  132. $a=new dotabase;
  133. // $a->search("nona","nama","merry");
  134. // echo "<br>";
  135. // $a->read("nona","WHERE status='lajang'");
  136. // echo "<br>";
  137. // $a->create("nona","gadis","shiro");
  138. // echo "<br>";
  139. // $a->update("nona","2","status","lajang");
  140. // echo "<br>";
  141. // $a->delete('nona',"2");
  142. // echo "<br>";
  143.  
  144.  
  145. // Disini Aksi Client
  146. $b=new Clients;
  147. // $b->CreateItem('Kolak','5000','kolaj.jpg','This is Drink From Indonesian');
  148. // echo "<br>";
  149. // $b->UpdateItem(2,"Kolak Pisang","5000","kolak.jpg","Indonesia Punya Bro/Sist");
  150. // echo "<br>";
  151.  
  152.  
  153.  
  154. // Disini Aksi Admin
  155. $c=new admin;
  156. // $c->userUpdate(2,"Bakhti","root");
  157. // echo "<br>";
  158. // $c->userDel(2);
  159. // echo "<br>";
  160. // $c->userAdd("Bakhti","root");
  161. // echo "<br>";
  162. // $c->userID(1);
  163. // echo "<br>";
  164. while ($fetch=$c->userAll()->fetch()) {
  165. echo $fetch['fullname'];
  166. }
  167.  
  168. // Maaf Masih Belajar
  169.  
  170.  
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement