PDO不会返回任何结果

时间:2016-04-15 10:47:12

标签: php mysql pdo

我正在创建函数并在index.php之后调用它们。其他部分工作,但当我尝试为此代码创建函数并调用时,没有任何返回,页面为空白。 index.php中的原始代码:

$abfrage1 = "SELECT c.area_id,c.title as comptitle,ta.name as taname,tb.name as tbname,m.date,m.time,scli.type as scli_type,scgo.type as scgo_type,m.match_id,m.status,m.match_id,m.final_period,a.country_code,u.user_name,m.team_a_id,m.team_b_id,m.score_a,m.score_b,s.competition_id,ROUND( TIMESTAMPDIFF(MINUTE, concat(m.date,' ',m.time),NOW() )) AS minutes_delay
FROM `match` m 
INNER JOIN round r ON m.round_id = r.round_id
INNER JOIN season s ON r.season_id = s.season_id
INNER JOIN round_coverage sc ON sc.round_id = r.round_id AND sc.coverage_type_id = '1' AND sc.type = 'Live'
$coverage_join
INNER JOIN competition c ON s.competition_id = c.competition_id
INNER JOIN users_comp uc ON c.competition_id = uc.competition_id
INNER JOIN area a ON c.area_id = a.area_id
INNER JOIN team ta ON ta.team_id = m.team_a_id
INNER JOIN team tb ON tb.team_id = m.team_b_id
LEFT JOIN users_match um ON um.match_id = m.match_id
LEFT JOIN users u ON um.user_id = u.user_id
LEFT JOIN match_checks mc ON mc.match_id = m.match_id
$innerjoin1
WHERE m.date <= DATE_ADD(CURDATE(),INTERVAL 1 DAY)  AND uc.user_id = '$userid' AND m.date >= DATE_SUB(CURDATE(),INTERVAL 2 DAY) AND m.date > '2014-11-30' AND m.status NOT IN  ('Postponed','Awarded','Cancelled') AND ((scgo.round_id > 0 AND mc.recheck1 IS NULL AND mc.recheck2 IS NULL) OR (scgo.round_id IS NULL AND concat(m.date,' ',m.time) > DATE_SUB(NOW(),INTERVAL 160 MINUTE)))
GROUP BY m.match_id
ORDER BY m.date ASC,m.time ASC,c.area_id ASC,r.season_id ASC,ta.name ASC"; 

$ergebnis1 = $dbh->query($abfrage1);
while ($row1 = $ergebnis1->fetch(PDO::FETCH_OBJ)) {
    //Other queries
}

在此查询中还有两个变量:

$ coverage_join:

if ($filter == 'liveli') {
$coverage_join = "INNER JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5' AND scli.type = 'Pre-Match'
INNER JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'  AND scgo.type = 'Live'";
} else {
$coverage_join = "LEFT JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5'
LEFT JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'";
}

$ innerjoin1:

if ($uid > 0) { $innerjoin1 = "INNER JOIN users_match umm ON umm.match_id = m.match_id AND umm.user_id = '$uid'"; }
else { $innerjoin1 = ""; }

我创建了新的storage.php并创建了函数:

public function getMain($coverage_join, $innerjoin1, $userid)
    {
        $query = "SELECT c.area_id,c.title as comptitle,ta.name as taname,tb.name as tbname,m.date,m.time,scli.type as scli_type,scgo.type as scgo_type,
                        m.match_id,m.status,m.match_id,m.final_period,a.country_code,u.user_name,m.team_a_id,m.team_b_id,m.score_a,m.score_b,s.competition_id,
                        ROUND( TIMESTAMPDIFF(MINUTE, concat(m.date,' ',m.time),NOW() )) AS minutes_delay
                    FROM `match` m 
                    INNER JOIN round r ON m.round_id = r.round_id
                    INNER JOIN season s ON r.season_id = s.season_id
                    INNER JOIN round_coverage sc ON sc.round_id = r.round_id AND sc.coverage_type_id = '1' AND sc.type = 'Live'
                    :cJoin
                    INNER JOIN competition c ON s.competition_id = c.competition_id
                    INNER JOIN users_comp uc ON c.competition_id = uc.competition_id
                    INNER JOIN area a ON c.area_id = a.area_id
                    INNER JOIN team ta ON ta.team_id = m.team_a_id
                    INNER JOIN team tb ON tb.team_id = m.team_b_id
                    LEFT JOIN users_match um ON um.match_id = m.match_id
                    LEFT JOIN users u ON um.user_id = u.user_id
                    LEFT JOIN match_checks mc ON mc.match_id = m.match_id
                    :iJoin
                    WHERE m.date <= DATE_ADD(CURDATE(),INTERVAL 1 DAY)  AND uc.user_id = :uId AND m.date >= DATE_SUB(CURDATE(),INTERVAL 2 DAY) AND m.date > '2014-11-30' AND m.status NOT IN  ('Postponed','Awarded','Cancelled') AND ((scgo.round_id > 0 AND mc.recheck1 IS NULL AND mc.recheck2 IS NULL) OR (scgo.round_id IS NULL AND concat(m.date,' ',m.time) > DATE_SUB(NOW(),INTERVAL 160 MINUTE)))
                    GROUP BY m.match_id
                    ORDER BY m.date ASC,m.time ASC,c.area_id ASC,r.season_id ASC,ta.name ASC";
        $statement = $this->db->prepare($query);
        $statement->execute([
            ':cJoin' => $coverage_join,
            ':iJoin' => $innerjoin1,
            ':uId' => $userid,
        ]);
        return $statement->fetchObject();
    }
index.php中的

我把:

if ($uid > 0) { $innerjoin1 = "INNER JOIN users_match umm ON umm.match_id = m.match_id AND umm.user_id = '$uid'"; }
else { $innerjoin1 = ""; }


if ($filter == 'liveli') {
$coverage_join = "INNER JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5' AND scli.type = 'Pre-Match'
INNER JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'  AND scgo.type = 'Live'";
} else {
$coverage_join = "LEFT JOIN round_coverage scli ON scli.round_id = r.round_id AND scli.coverage_type_id = '5'
LEFT JOIN round_coverage scgo ON scgo.round_id = r.round_id AND scgo.coverage_type_id = '6'";
}

while ($row1 = $storage_access->getMain($coverage_join, $innerjoin1, $userid)) {
 // Other query
}

“$ storage_access”工作正常,我用函数调用的其他查询都有效。我无法找到这个问题的解决方案,我希望你能告诉我为什么它不起作用。提前谢谢。

编辑:while {}循环中有一些函数使用$ row1,例如:

$row11 = $storage_access->getGoalScorersA($row1);

0 个答案:

没有答案