I'm trying to do some complex SQL that requires me to set a couple of variables in MySQL in one statement and then executing a query that relies on them in the next statement. For this I need to send these commands to the database in a single $Model->query() call.
The two-statement call looks similar to this, pasted from this tutorial:
set @num := 0, @type := '';
select type, variety, price,
@num := if(@type = type, @num + 1, 1) as row_number,
@type := type as dummy
from fruits force index(type)
group by type, price, variety
having row_number <= 2;
Interestingly, I cannot find a way to execute multiple semi-colon-separated SQL statements through any CakePHP model method (something like mysqli::multi_query). It appears that the query() method only executes the first statement in this multi-statement call.
How do I execute both in the same call?