我有一个SQL查询在PhpMyAdmin上完美运行,但在PHP中它返回“为foreach()提供的无效参数”......这是代码:
$materia=$_GET["m"];
$sqlquery = "select m.cod, m.titulo, m.texto, m.olho, day(m.datahora), month(m.datahora), year(m.datahora), hour(m.datahora), minute(m.datahora), g.descricao, g.cod from fs_materia as m, fs_grupo as g where (g.cod=m.codlocal and m.cod=$materia)";
echo $sqlquery.'</br></br>';
foreach ($banco->query($sqlquery) as $dados) {
如果仔细观察,你会发现我甚至已经回复了SQL查询,所以我可以复制到PHPMyAdmin ......它可以工作。
我不明白......
答案 0 :(得分:-1)
尝试使用它:
...
$sqlquery = "select m.cod, m.titulo, m.texto, m.olho, day(m.datahora), month(m.datahora), year(m.datahora), hour(m.datahora), minute(m.datahora), g.descricao, g.cod from fs_materia as m, fs_grupo as g where (g.cod=m.codlocal and m.cod = :materia)";
$banco->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $banco->prepare($sqlquery);
$sth->execute(array(':materia' => (int)$materia));
$result = $sth->fetchAll();
foreach ($result as $dados) {
...
提到alredy时,你总是很高兴:
点击此链接:Gone Away