Wrapped the code in
[code]...[/code] forum tags. 🙂
I don't think you can do multiple queries (separated by
;) in one
$pdo->query(). I'm not familiar with that
set @fn type of thing, so don't know off hand if this could be done somehow via separate queries (maybe within a transaction), or if it would be better to define a database stored function then call that, or...?
Of course, another alternative would be to run the select query, then loop through the result set and output to CSV via the PHP
fputcsv() function, perhaps. 🤷