Advertisement
oimtrust

class.profile.php_crudImage-pdo-oop

Jan 2nd, 2017
1,700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. <?php
  2.     require_once 'database.php';
  3.  
  4.     /**
  5.      * Profile Class
  6.      */
  7.     class Profile
  8.     {
  9.         private $conn;
  10.         public function __construct()
  11.         {
  12.             $database   = new Database();
  13.             $db         = $database->dbConnection();
  14.             $this->conn = $db;
  15.         }
  16.  
  17.         public function runQuery($sql)
  18.         {
  19.             $stmt = $this->conn->prepare($sql);
  20.             return $stmt;
  21.         }
  22.  
  23.         public function insertProfile($nama, $photo)
  24.         {
  25.             try {
  26.                 $stmt = $this->conn->prepare(
  27.                         "INSERT INTO profile(nama,photo)
  28.                         VALUES(:nama,:photo)"
  29.                     );
  30.                 $stmt->bindParam(':nama', $nama);
  31.                 $stmt->bindParam(':photo', $photo);
  32.                 $stmt->execute();
  33.  
  34.                 return $stmt;
  35.             } catch (PDOException $e) {
  36.                 echo $e->getMessage();
  37.             }
  38.         }
  39.  
  40.         public function updateProfile($nama, $photo, $ipro)
  41.         {
  42.             try {
  43.                 $stmt = $this->conn->prepare(
  44.                         "UPDATE profile
  45.                         SET nama=:nama,
  46.                             photo=:photo
  47.                         WHERE id_profile=:ipro"
  48.                     );
  49.  
  50.                 $stmt->bindParam(':nama', $nama);
  51.                 $stmt->bindParam(':photo', $photo);
  52.                 $stmt->bindParam(':ipro', $ipro);
  53.                 $stmt->execute();
  54.  
  55.                 return $stmt;
  56.             } catch (PDOException $e) {
  57.                 echo $e->getMessage();
  58.             }
  59.         }
  60.  
  61.         public function deleteProfile($ipro)
  62.         {
  63.             if (isset($_GET['delete_ipro'])) {
  64.                 $stmt = $this->conn->prepare(
  65.                         "DELETE FROM profile WHERE id_profile=:ipro"
  66.                     );
  67.  
  68.                 $stmt->bindParam(':ipro', $_GET['delete_ipro']);
  69.                 $stmt->execute();
  70.  
  71.                 return $stmt;
  72.             }
  73.         }
  74.  
  75.         public function redirect($url, $statusCode = 303)
  76.         {
  77.             header('Location: ' . $url, true, $statusCode);
  78.             die();
  79.         }
  80.     }
  81.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement