SHARE
TWEET

Untitled

a guest Jan 28th, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class DB{
  2.      private $host="localhost";
  3.      private $user="root";
  4.      private $db="primax";
  5.      private $pass="";
  6.      private $conn;
  7.      public function __construct(){
  8.      $this->conn = new PDO("mysql:host=".$this->host.";dbname=".$this->db,$this->user,$this->pass);
  9.      };
  10.  
  11.  
  12. class crud extends DB {
  13.      public function showData($table){
  14.      $sql="SELECT * FROM $table";
  15.      $q = $this->conn->query($sql) or die("failed!");
  16.      while($r = $q->fetch(PDO::FETCH_ASSOC)){
  17.      $data[]=$r;
  18.      }
  19.      return $data;
  20.      }
  21.      public function getById($id,$table){
  22.      $sql="SELECT * FROM $table WHERE id = :id";
  23.      $q = $this->conn->prepare($sql);
  24.      $q->execute(array(':id'=>$id));
  25.      $data = $q->fetch(PDO::FETCH_ASSOC);
  26.      return $data;
  27.      }
  28.  
  29.      public function update($id,$name,$email,$mobile,$address,$table){
  30.  
  31.     $sql = "UPDATE $table
  32.      SET name=:name,email=:email,mobile=:mobile,address=:address
  33.      WHERE id=:id";
  34.      $q = $this->conn->prepare($sql);
  35.      $q->execute(array(':id'=>$id,':name'=>$name,
  36.     ':email'=>$email,':mobile'=>$mobile,':address'=>$address));
  37.      return true;
  38.      }
  39.      public function insertData($name,$email,$mobile,$address,$table){
  40.      $sql = "INSERT INTO $table SET name=:name,email=:email,mobile=:mobile,address=:address";
  41.      $q = $this->conn->prepare($sql);
  42.      $q->execute(array(':name'=>$name,':email'=>$email,
  43.     ':mobile'=>$mobile,':address'=>$address));
  44.      return true;
  45.      }
  46.  
  47.      public function deleteData($id,$table){
  48.  
  49.      $sql="DELETE FROM $table WHERE id=:id";
  50.      $q = $this->conn->prepare($sql);
  51.      $q->execute(array(':id'=>$id));
  52.      return true;
  53.      }
  54. }
  55.     ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top