I have the following code:
$sql = "SELECT table.field, table2.field2 FROM
table, table2";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$x = $stmt->fetchAll(PDO::FETCH_ASSOC);
I know it is not enough information, but I do not understand why the code executes only if I comment the fetchAll line. When that line executes, I do not get anything, just blank browser, no errors or anything. In firebug the response is blank… What can it be??
You are doing a Cartesian product of
tableandtable2. This can be a HUGE amount of data.For each row in table, you are getting all the rows in
table2. So iftablehas 100 lines, and table2 has 500 lines, your query will try to fetch 50.000 lines.You’ll either want a JOIN:
Or a UNION
If a Cartesian product is really what you want, try adding a LIMIT and see if that works. Then later increase or remove the limit
Depending on what your tables contain (you indeed did not give enough info).