I have a super extensive query when I try to insert into the database does not work, I don’t know why

Asked

Viewed 37 times

0

$result = $db->query("
                SELECT RES.morada, RES.espaco, SUM(DATEDIFF(RES.data_fim, RES.data_inicio)*RES.tarifa) AS pago
                FROM (
                    SELECT A.morada AS morada, A.codigo AS espaco, A.data_inicio, O.data_fim, O.tarifa
                    FROM Aluga A, Espaco E, Oferta O, Estado ES
                    WHERE A.morada ='IST' AND A.morada = E.morada AND A.morada = O.morada AND A.codigo = E.codigo AND A.codigo = O.codigo AND A.data_inicio = O.data_inicio AND A.numero = ES.numero AND ES.estado = 'Paga'
                    UNION
                    SELECT P.morada AS morada, P.codigo_espaço AS espaco, A.data_inicio, O.data_fim, O.tarifa
                    FROM Aluga A, Posto P, Oferta O, Estado ES
                    WHERE A.morada ='IST' AND A.morada = P.morada AND A.morada = O.morada AND A.codigo = P.codigo AND A.codigo = O.codigo AND A.data_inicio = O.data_inicio AND A.numero = ES.numero AND ES.estado = 'Paga'
                    ) AS RES
                GROUP BY RES.morada, RES.espaco;
  • 1

    insert what? error appears?

  • No error message appears, but I made a print after this query echo "went through here"

  • and this message does not appear

  • Do so to see if any error appears $db->query("consulta longa...") or die($db->error); or or die(print_r($db->errorInfo())); is using PDO or Mysqli?

  • I’m using PDO

No answers

Browser other questions tagged

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