My select statement looks somewhat like this :
CREATE TEMPORARY TABLE t1 AS(
SELECT id, COUNT(*) AS count
FROM some_other_table
GROUP BY id);
ALTER TABLE t1 ADD UNIQUE INDEX (id);
SELECT * FROM t2 INNER JOIN t1 ON t1.id = t2.id
I'm using the following PHP code :
$pdo->query($sql)->fetchAll();
But I get an error since PDO does not allow multiple statements' execution in one query.
From what I've read so far, I should use exec(). But then exec() does not return results for select statement. I do not need the parametrization for this specific query so any unsafe method will work too, since the query itself is perfectly safe from any outside alteration.
Right now what I'm doing is executing the sql code as 3 different statements. but I believe that's slower than executing it in one go and would like to find a better method to do this.