Mysql Query with mysql variable not working in Zend Framework 1

后端 未结 1 919
遇见更好的自我
遇见更好的自我 2021-01-15 23:07

Zend config is : resources.db.adapter = \"pdo_mysql\"

the query that gets Message: SQLSTATE[HY000]: General error

$db = Zend_Db_Tab         


        
1条回答
  •  执念已碎
    2021-01-15 23:43

    It seems setting a variable in MySql is considered a separate query. ( fetch*() cannot handle multiple calls)

    so for those with this kind of issue:

    $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"
                                );
    

    0 讨论(0)
提交回复
热议问题