Advertisement
darryljf

recipe.class.php

Apr 7th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. class Recipe{
  4.   protected $Conn;
  5.  
  6.   public function __construct($Conn){
  7.     $this->Conn = $Conn;
  8.   }
  9.  
  10.   public function addRecipe($data){
  11.  
  12.     $query = "INSERT INTO recipes (recipe_name, recipe_image, recipe_instructions, cat_id, user_id) VALUES (:recipe_name, :recipe_image, :recipe_instructions, :cat_id, :user_id)";
  13.     $stmt = $this->Conn->prepare($query);
  14.    
  15.     $data['user_id'] = $_SESSION['user_data']['user_id'];
  16.     $data['recipe_image'] = $_FILES['recipe_image']['tmp_name'];
  17.    
  18.     return $stmt->execute($data);
  19.   }
  20.  
  21.   public function getRecipesForCat($cat_id) {
  22.  
  23.     $query = "SELECT * FROM recipes WHERE cat_id = :cat_id";
  24.     $stmt = $this->Conn->prepare($query);
  25.     $stmt->execute(array(':cat_id'=>$cat_id));
  26.     return $stmt->fetchAll(PDO::FETCH_ASSOC);
  27.   }
  28.  
  29.   public function getRecipesForUser($user_id){
  30.  
  31.     $query = "SELECT recipe_id, recipe_name, recipe_instructions FROM recipes WHERE user_id = :user_id";
  32.     $stmt = $this->Conn->prepare($query);
  33.     $stmt->execute(array(':user_id'=>$user_id));
  34.     return $stmt->fetchAll(PDO::FETCH_ASSOC);
  35.  
  36.   }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement