4
Colleagues, I have a connection class:
class Conecta
{
    private $Servidor = '127.0.0.1';
    private $Usuario = 'root';
    private $Senha = 'senha';
    private $Banco = 'banco';
    // Protegido
    protected $Conecta;
    // Faz a conexão
    public function conectar(){
$this->Conecta = mysqli_connect($this->Servidor,$this->Usuario,$this->Senha,$this->Banco);
}
And I have a class of methods:
    class Metodos extends Conecta
    {
       // Primeiro método
      public functionPrimeiro(){
           $conectar = new Conecta();
            $conectar->conectar();
    $sql = mysqli_query($conectar->conectar(), "MINHA QUERY");
    }
    // Segundo método
      public functionSegunda(){
           $conectar = new Conecta();
            $conectar->conectar();
    $sql = mysqli_query($conectar->conectar(), "MINHA QUERY");
    }
}
Notice that within each method I use:
   $conectar = new Conecta();
    $conectar->conectar();
Would there be some way I wouldn’t use within each method or might just be that way?
Hello bfavaretto, unfortunately I can not uncouple, because in other parts of the system is already using this way.
– user24136
@Jose.Marcos I’m sorry, but your code is so wrong, I would rethink it and redo where I had to change.
– Maniero
Enjoy while you can, because the POO is basically about reusing codes.
– Edilson
Hello bigown, I agree with you, but unfortunately the system was already ready here in the company and if I change now, I would have to redo it almost completely and it would take time.
– user24136