Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/slutprojekt/class/

categoryClass.php
recipeClass.php

categoryClass.php

27 lines ASCII Windows (CRLF)
<?php

Class Category {

  private 
$dbconn;

  public function 
__construct($dbconn) {
    
$this->dbconn $dbconn
  }

  public function 
createCategory($name) {
    try {
      
$sql "INSERT INTO categories (name) 
        VALUES (:name)"
;
      
$stmt $this->dbconn->prepare($sql);
      
$stmt->execute([
        
':name' => $name
      
]);

      return 
true;
    } catch (
PDOException $e) {
      return 
"Fel vid skapande av kategori: " $e->getMessage();
    }
  }
}
?>