<?php 

  class Model{
    private $nombre;
    private $descripcion;
    private $fecha_creacion;
    private $conexion;

    private $esquema = "sicanets_solidez_desarrollo";

    public function __construct(){
      $this->conexion = new Conexion();
    }
    
    public function get($atributo){
      return $this->$atributo;
    }

    public function set($atributo,$valor){
      $this->$atributo = $valor;
    }

    public function listar_tablas(){
      $sql = "SELECT TABLE_NAME AS nombre,TABLE_COMMENT AS descripcion,CREATE_TIME AS fecha_creacion FROM information_schema.tables WHERE table_schema = '$this->esquema' ";
      return $this->conexion->consultaRetorno($sql);
    }

    public function listar_tablas_x_campo($nombre_campo){
      $nombre_campo=trim($nombre_campo);
      $sql="SELECT TABLE_NAME AS nombre,TABLE_COMMENT AS descripcion,CREATE_TIME AS fecha_creacion FROM information_schema.tables WHERE table_schema = '$this->esquema' AND TABLE_NAME IN (SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA = '$this->esquema' AND COLUMN_NAME ='$nombre_campo')";
      if (empty($nombre_campo)) {
        $sql = "SELECT TABLE_NAME AS nombre,TABLE_COMMENT AS descripcion,CREATE_TIME AS fecha_creacion FROM information_schema.tables WHERE table_schema = '$this->esquema' ";
      }
      return $this->conexion->consultaRetorno($sql);
    }

    public function listar_campos($nombre_tabla){
      $nombre_tabla = trim($nombre_tabla);
      $sql="SELECT COLUMN_NAME AS nombre, COLUMN_TYPE AS tipo, COLUMN_DEFAULT AS valor_default, IS_NULLABLE AS acepta_null, COLUMN_KEY AS es_key, EXTRA AS extra, COLUMN_COMMENT AS descripcion FROM information_schema.columns WHERE TABLE_NAME='$nombre_tabla' AND TABLE_SCHEMA = '$this->esquema' ";
      return $this->conexion->consultaRetorno($sql);
    }

    public function close_db() {
      return $this->conexion->db_close();
    }

  }

 ?>