MySql Select不适用于php

时间:2019-06-19 07:15:47

标签: php mysql select foreach

我想用pdo在PHP中执行MySQL select。 在我在select中声明一个SQL变量之前,此方法工作正常。当我在选择中添加SET @variable = value;部分时,它不再起作用。

那是如何工作的:

$sqlGa = "SELECT id, teamName, games, points, goals, goalsAgainst, difference
FROM tbl_penaltycompetition
WHERE teamGroup = 'A'
ORDER BY points DESC, difference DESC, goals DESC";
foreach ($pdo->query($sqlGa) as $row) {
...
}

并且这种方式不再起作用了((phpmyadmin中的(数组为空),此选择仍然有效):

$sqlGa = "SET @row_number = 0; 
SELECT (@row_number:=@row_number + 1) AS placement, id, teamName, games, points, goals, goalsAgainst, difference
FROM tbl_penaltycompetition
WHERE teamGroup = 'A'
ORDER BY points DESC, difference DESC, goals DESC"
foreach ($pdo->query($sqlGa) as $row) {
...
}

对不起,我的英语不好,我希望你们能听懂我想说的话...

感谢您的帮助!

0 个答案:

没有答案