<?php 
require_once "conexion.php";
class ModeloMembresia{


  static public function mdlInformacionMembresia(){
    $stmt=Conexion::conectar()->prepare("select * from membresia");
    $stmt->execute();

    return $stmt->fetchAll();

    $stmt->close();
    $stmt->null;
  }

  static public function mdlRegMembresia($data){
    $descripcion=$data["descripcion"];
    $costo=$data["costo"];

    $stmt=Conexion::conectar()->prepare("insert into membresia(descripcion, costo) values('$descripcion', '$costo')");

    if($stmt->execute()){
      return "ok";
    }else{
      return "error";
    }
    $stmt->close();
    $stmt->null;
  }

  static public function mdlInfoMembresia($id){
    $stmt=Conexion::conectar()->prepare("select * from membresia where id_membresia=$id");
    $stmt->execute();
    return $stmt->fetch();
    $stmt->close();
    $stmt->null;
  }

  static public function mdlEditMembresia($data){
    $idMembresia=$data["idMembresia"];
    $descripcion=$data["descripcion"];
    $costo=$data["costo"];
    $estado = $data["estado"];

    $stmt=Conexion::conectar()->prepare("update membresia set descripcion='$descripcion', costo='$costo', estado='$estado' where id_membresia=$idMembresia");

    if($stmt->execute()){
      return "ok";
    }else{
      return "error";
    }
    $stmt->close();
    $stmt->null;
  }

  static public function mdlEliMembresia($id){
    try{
      $Membresia=Conexion::conectar()->prepare("delete from membresia where id_membresia=$id");
      $Membresia->execute();
    }catch (PDOException $e){
      $codeError= $e->getCode();
      if($codeError=="23000"){
        return "error";
        $stmt->close();
        $stmt->null;
      }
    }
    return "ok";
    $stmt->close();
    $stmt->null;
  }
}