jojacafe
5/4/2017 - 3:35 PM

Class template CRUD database

Class template CRUD database

<?php

if (!class_exists('Core')) {
    require_once 'Core.php';
}

class Tag
{
    private $pdoCore = null;

    function __construct() {
        $this->pdoCore = Core::getInstance();
    }

    public function addTags($name, $icon, $comment) {
        $stmt = $this->pdoCore->db->prepare(
            "INSERT INTO TAG "
            . "(TAG_value, TAG_icon, TAG_comment) "
            . "VALUES (:TAG_value, :TAG_icon, :TAG_comment) "
        );
        $stmt->execute([
            ':TAG_value' => $name,
            ':TAG_icon' => $icon,
            ':TAG_comment' => $comment
        ]);
    }

    public function getTags() {
        $stmt = $this->pdoCore->db->prepare(
            "SELECT * FROM TAG"
        );
        $stmt->execute();

        return $stmt->fetchAll();
    }

    public function editTags($id, $name, $icon, $comment) {
        $stmt = $this->pdoCore->db->prepare(
            "UPDATE TAG SET "
            . "TAG_value = :TAG_value, "
            . "TAG_icon = :TAG_icon, "
            . "TAG_comment = :TAG_comment "
            . "WHERE TAG_id = :TAG_id "
        );
        $stmt->execute([
            ':TAG_id' => $id,
            ':TAG_value' => $name,
            ':TAG_icon' => $icon,
            ':TAG_comment' => $comment
        ]);
    }

    public function deleteTags($id) {
        $stmt = $this->pdoCore->db->prepare(
            "DELETE FROM TAG "
            . "WHERE TAG_id = :TAG_id "
        );

        $stmt->execute([
            ':TAG_id' => $id,
        ]);
    }

    public function getTagsByHouse($idCasa) {

    }
}