emprit

crudoop

Jul 13th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. //prototype crud sederhana
  2.     class User {
  3.             protected $table = 'user';
  4.      
  5.             public function read(){
  6.                     $sql = "select * from ". $this->table;
  7.                     //run sql code here
  8.                     echo "result of records";
  9.             }
  10.      
  11.             public function create($name){
  12.                     $sql = "insert into ".$this->table." (name) values('".$name."')";
  13.                     //run the sql code here
  14.                     echo "create function";
  15.             }
  16.      
  17.             public function update($id,$name){
  18.                     $sql = "update ".$this->table. " set name = '$name' where id=".$id;
  19.                     //run the sql code here
  20.                     echo "update record by id";
  21.             }
  22.      
  23.             public function delete($id){
  24.                     $sql = "delete ".$this->table ." where id = ".$id;
  25.                     //run the sql code here
  26.                     echo "delete record by id";
  27.      
  28.             }
  29.     }
  30.      
  31.     //example usage
  32.      
  33.     $user = new User();
  34.      
  35.     $user->create('rifaqu');
  36.     $user->read();
  37.     $user->update(1,'new name');
  38.     $user->delete(1); //by id;
Advertisement
Add Comment
Please, Sign In to add comment