1 line
No EOL
1.6 KiB
PHP
1 line
No EOL
1.6 KiB
PHP
<?php
|
|
|
|
/** Defino o local onde esta a classe */
|
|
namespace vendor\model;
|
|
|
|
class Geral
|
|
{
|
|
/** Declaro as variavéis da classe */
|
|
private $connection = null;
|
|
private $Main = null;
|
|
private $sql = null;
|
|
private $stmt = null;
|
|
|
|
private $table = null;
|
|
private $primaryKey = null;
|
|
private $primaryKeyValue = null;
|
|
private $column = null;
|
|
|
|
/** Construtor da classe */
|
|
function __construct()
|
|
{
|
|
|
|
/** Cria o objeto de conexão com o banco de dados */
|
|
$this->connection = new Mysql();
|
|
|
|
/** Instânciamento de classes */
|
|
$this->Main = new Main();
|
|
|
|
}
|
|
|
|
/** Busca genérica de registro */
|
|
public function Get(string $table, string $primaryKey, string $column, int $primaryKeyValue) : ? string
|
|
{
|
|
|
|
/** Parâmetros de Entrada */
|
|
$this->table = $table;
|
|
$this->primaryKey = $primaryKey;
|
|
$this->primaryKeyValue = $primaryKeyValue;
|
|
$this->column = $column;
|
|
|
|
/** Consulta SQL*/
|
|
$this->sql = "SELECT {$this->column} AS CAMPO FROM {$this->table} WHERE {$this->primaryKey} = :primaryKeyValue";
|
|
|
|
/** Preparo o SQL para execução */
|
|
$this->stmt = $this->connection->connect()->prepare($this->sql);
|
|
|
|
/** Preenchimento dos parâmetros */
|
|
$this->stmt->bindParam(':primaryKeyValue',$this->primaryKeyValue);
|
|
|
|
/** Executo o SQL */
|
|
$this->stmt->execute();
|
|
|
|
/** Retorno em formato de obeto */
|
|
return $this->stmt->fetchObject()->CAMPO;
|
|
|
|
}
|
|
|
|
|
|
/** Fecha uma conexão aberta anteriormente com o banco de dados */
|
|
function __destruct()
|
|
{
|
|
|
|
$this->connection = null;
|
|
|
|
}
|
|
|
|
}
|