<?php
namespace count_form\app\entity;

use count_form\app\db\Main;

class request extends Main
{
    public function getAllData()
    {

        $sql =
            '
                SELECT * FROM
                    request
                ORDER BY
                     id ASC';
        $result = $this->db->query($sql);

        return $result->fetchAll(\PDO::FETCH_ASSOC);
    }







    public function getOneData($id)
    {

        $sql =
            '
                SELECT * FROM
                    request
                WHERE
                    id = :id
            ';
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(":id", $id);
        $stmt->execute();
        return $stmt->fetch(\PDO::FETCH_ASSOC);
    }

    public function deleteData($id){
        $sql =
            '   DELETE
                FROM
                    request
                WHERE
                    id  = :id
            ';
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(":id", $id);
        $stmt->execute();
    }

    public function addData($email, $text)
    {
        $sql =
            '
                INSERT INTO
                    request
                        (
                            text,
                            email
                        )
                        VALUES
                        (
                            :text,
                            :email
                        )
            ';

        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(":text", $text);
        $stmt->bindValue(":email", $email);
        $stmt->execute();
        return $this->db->lastInsertId();



    }

    public function UpdateData($data,$id)
    {

        $sql =
            '
                UPDATE
                   request
                SET
                            text = :text,
                            email = :email
                WHERE
                    id              = :id
            ';
        $stmt = $this->db->prepare($sql);
        $stmt->bindValue(":id", $id);
        $stmt->bindValue(":text", $data['text']);
        $stmt->bindValue(":email", $data['email']);
        $stmt->execute();
    }






}