1

Zendの構成は次のとおりです:resources.db.adapter = "pdo_mysql"

メッセージを取得するクエリ :SQLSTATE [HY000]:一般エラー

$db = Zend_Db_Table::getDefaultAdapter();
        $db->setFetchMode(Zend_Db::FETCH_ASSOC);       


        $qry =  $db->fetchAll(" SET @rank = 0 ;
                                SELECT
                                   @rank := @rank +1 AS rank,
                                    SUM(user_scoring_data.user_points)  AS user_points,
                                    league_team.user_id

                                FROM league_team 
                                RIGHT JOIN user_scoring_data ON league_team.league_team_id = user_scoring_data.league_team_id

                                WHERE league_id = '$league_id' GROUP BY user_scoring_data.league_team_id 
                                ORDER BY user_points DESC"
                            );

mysql変数を削除すると、機能します。

$db->fetchAll("
                                SELECT
                                    SUM(user_scoring_data.user_points)  AS user_points,
                                    league_team.user_id

                                FROM league_team 
                                RIGHT JOIN user_scoring_data ON league_team.league_team_id = user_scoring_data.league_team_id

                                WHERE league_id = '$league_id' GROUP BY user_scoring_data.league_team_id 
                                ORDER BY user_points DESC"
                            );

*注:クエリはphpmyadminで直接テストされており、エラーはありません。

4

1 に答える 1

6

MySqlに変数を設定することは、別のクエリと見なされるようです。(fetch *()は複数の呼び出しを処理できません)

したがって、この種の問題を抱えている人のために:

$db->query("SET @rank = 0 ;");

$db->fetchAll("SELECT
                                   @rank := @rank +1 AS rank,
                                    SUM(user_scoring_data.user_points)  AS user_points,
                                    league_team.user_id

                                FROM league_team 
                                RIGHT JOIN user_scoring_data ON league_team.league_team_id = user_scoring_data.league_team_id

                                WHERE league_id = '$league_id' GROUP BY user_scoring_data.league_team_id 
                                ORDER BY user_points DESC"
                            );
于 2012-10-18T12:20:36.100 に答える