<?php



/**

 * <b>Delete.class:</b>

 * Classe responsavel por leituras geréticos o banco dados!

 * 

 * @copyright (c) 2017, Welton Doe

 */

class Delete extends Conn {



    private $Tabela;

    private $Termos;

    private $Places;

    private $Result;



    /** @var PDOStatement */

    private $Delete;



    /** @var PDO */

    private $Conn;



    public function ExeDelete($Tabela, $Termos, $ParseString) {

        $this->Tabela = (string) $Tabela;

        $this->Termos = (string) $Termos;

        

        parse_str($ParseString, $this->Places);

        $this->getSyntax();

        $this->Execute();

    }



    public function getResult() {

        return $this->Result;

    }

    

    public function getRowCount(){

        return $this->Delete->rowCount();

    }

        

    public function setPlaces($ParseString){

        parse_str($ParseString, $this->Places);

        $this->getSyntax();

        $this->Execute();

    }



    /**

     * ****************************************

     * ********** PRIVATE METHODS *************

     * ****************************************

     */

    // obtem o PDO Prepara a query

    private function Connect() {

        $this->Conn = parent::getConn();

        $this->Delete = $this->Conn->prepare($this->Delete);

    }

    

    // Cria a sintaxe da query para Prepared statements

    private function getSyntax() {

        

        $this->Delete = "DELETE FROM {$this->Tabela} {$this->Termos}";

    }



    //obtém  a conexão e a syntax, executa a query!

    private function Execute() {

        $this->Connect();

        try {

            $this->Delete->execute($this->Places);

            $this->Result = true;

        } catch (PDOException $e) {

            WSErro("<b> Erro ao DELETAR:</b> {$e->getMessage()}", $e->getCode());

        }

    }



}