CONCAT de querys DELETE?

Asked

Viewed 42 times

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’d 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 2 searches only 1.

Like?

Kind of a CONCAT...

  • 1

    If you do DELETE FROM plano, fotos ... does not work? Or then change the end of sql to idPlano = $idPlano;"; adding a ; at the end of the string

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 find out if the foreclosure was or was not performed.

In the case, in the Mysql returns 1 or 2

0

If I’m not mistaken:

$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 the WHERE for table pictures was just put a nome_da_tabela.nome_do_campo='comparador'

  • 1

    or test and then I’ll talk.

  • So, it didn’t work! Any other idea? It didn’t even delete the items from the flat table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.