CONCAT of querys DELETE?

1

I have the following function :

 public function excluir ($idPlano) {        

     $string1 = "DELETE FROM planos WHERE idPlano = ".$idPlano;
     $string2 = "DELETE FROM fotos WHERE idPlano = ".$idPlano;

     $this->conexao->query($string1);
     $this->conexao->query($string2);

 }

I would like to do something like:

 public function excluir ($idPlano) {        

     $string = "DELETE FROM planos WHERE idPlano = ".$idPlano;
     $string .= "DELETE FROM fotos WHERE idPlano = ".$idPlano;

     return $this->conexao->query($string) ? 1 : 2;

 }

Do only 2 searches.

Is it like this?

Kind that a CONCAT ...

    
asked by anonymous 22.05.2018 / 22:38

2 answers

1
     public function excluir ($idPlano) {        

     $string = "DELETE planos, fotos FROM planos
                LEFT JOIN fotos  ON 
                    planos.idPlano = fotos.idPlano
                WHERE planos.idPlano = ".$idPlano;

     return $this->conexao->query($string);

 }

The return is just to know if exclusion has been performed or not.

In case, MySQL returns 1 or 2

    
23.05.2018 / 14:27
0

If I'm not mistaken it's like this:

$string1 = "
    DELETE planos.*,fotos.*
    FROM planos,fotos
    WHERE planos.idPlano = '$idPlano' AND planos.idPlano = fotos.idPlano 
";
$this->conexao->query($string1);

If there was another condition in WHERE for table photos, just put a nome_da_tabela.nome_do_campo='comparador'

    
22.05.2018 / 23:02