I'm trying to run a combination of queries from PHP. Something like this:
SELECT @rownum:=0; INSERT INTO tbl1 (`myId`, `rank`) (SELECT myId, @rownum:=@rownum+1 FROM `tbl2` WHERE 1 ORDER BY rank DESC)
Because of the user-defined var (@rownum) I have to run these queries "together". I've tried doing it either with mysqli or PDO, but both seemed to block this.
The mysqli usage I tried was:
public function multiQuery($query) {
if (@parent::multi_query($query)) {
$i = 0;
do {
$i++;
} while (@parent::next_result());
}
if (!$result) {
printf("MySQLi error:<br><b>%s</b><br>%s <br>", $this->error, $query);
}
return $result;
}
And in PDO I just expected it to work with the query()
func.
How can I overcome this?