ConnectionBanco.class.php
class conexaoBanco{
private $host="asd";
private $login="a131";
private $senha="123123";
private $banco="asdasdasd";
private $conn;
public function dbConexao(){
$this->conn = new PDO(
'mysql:host='.$this->host.'; dbname=' .$this->banco.";charset=utf8", $this->login, $this->senha);
$this->conn->exec("SET NAMES 'utf8';");
return $this->conn;
}
}
CRUD.class.php
include_once("conexaoBanco.class.php");
class CRUD {
private $db;
private $tabela = null;
public function __construct(){
$this->db = new conexaoBanco();
$this->db = $this->db->dbConexao();
}
public function showAll($tabela,$where){
$query = "SELECT * FROM $tabela WHERE $where";
$sth = $this->db->prepare($query);
$sth->execute();
return $sth;
}
}
running:
$sth = $sth->showAll($tabela, "status=0 GROUP BY perfil ASC");
What good practices to build a better CRUD?