嘿那里我正在尝试将我的php sql查询代码从mysqli更改为PDO,因为我可以自己注入它。 mysqli代码正在寻找l
$result = $mysqli->query($sql) or die($mysqli->error);
while ( $row = $result->fetch_assoc() ){
$output[] = $row;
}
echo json_encode($output);`
像这样的PDO代码
$statement=$pdo->prepare($sql);
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($result);
这是查询:
Select s.*, t.team_name as team_1_name, t1.team_name as team_2_name from spiele s,
teams t, teams t1, gruppen g, kategorien k where s.team_1=t.team_id and
t.gruppen_id=g.gruppen_id and g.kategorien_id=k.kategorien_id and k.kat_name='".$kat."'
and s.team_2=t1.team_id
Union Select s.*, t.team_name as team_1_name, t1.team_name as team_2_name from
gruppenfinalspiele s, gruppenfinalteams t1, gruppenfinalteams t, gruppen g, kategorien k
where s.team_1=t.finalteam_id and t.gruppen_id=g.gruppen_id and
g.kategorien_id=k.kategorien_id and k.kat_name='".$kat."' and s.team_2=t1.finalteam_id
Union Select s.*, t.team_name as team_1_name, t1.team_name as team_2_name from
halbfinalspiele s, halbfinalteams t, halbfinalteams t1, kategorien k where
s.team_1=t.finalteam_id and t.kategorien_id=k.kategorien_id and k.kat_name='".$kat."'
and s.team_2=t1.finalteam_id
Union Select s.finalspiel_id, s.team_1, s.team_2, s.spielzeit, s.feld, s.tore_1, s.tore_2,
s.sieger, s.placeholder_team_1 as team_1_name, s.placeholder_team_2 as team_2_name from
finalspiele s, kategorien k where s.kategorien_id=k.kategorien_id and
k.kat_name='".$kat."'
ORDER BY spielzeit, Feld
这些是第一行结果: 对于mysqli:
[{"spiel_id":"2","team_1":"1","team_2":"2","spielzeit":"18:00:00","feld":"A",
"tore_1":"0","tore_2":"4","sieger":"2","team_1_name":"Los Ventilos Oberdorf",
"team_2_name":"Sambaschr\u00e4nzer Bubendorf 2"},
和PDO:
{"spiel_id":"2","team_1":"1","team_2":"2","spielzeit":"18:00:00","feld":"A",
"tore_1":"0","tore_2":"4","sieger":"2","team_1_name":"Los Ventilos Oberdorf",
"team_2_name":null}
现在的问题是最后一个Value(team_2_name)为null。有人可以告诉我为什么或我需要改变什么?
由于