如何从原始查询中获取 sql 结果

How to get sql result from raw query

获取 SQL 的错误导致 codeIgniter。当我在 phpmyadmin 中使用相同的查询时,我成功地得到了结果。 怎么了,求助

型号:

public function calculateScore()
{
    $team_points = $this->db->query('SELECT teams.team_name,
                                        COUNT(matches.winner) AS Win
                                    FROM
                                        matches
                                    RIGHT JOIN teams ON teams.team_name = matches.winner
                                    GROUP BY teams.team_name, matches.winner
                                    ORDER BY win DESC');

    return $team_points;
}

错误:

{
    "conn_id": {
        "affected_rows": null,
        "client_info": null,
        "client_version": null,
        "connect_errno": null,
        "connect_error": null,
        "errno": null,
        "error": null,
        "error_list": null,
        "field_count": null,
        "host_info": null,
        "info": null,
        "insert_id": null,
        "server_info": null,
        "server_version": null,
        "sqlstate": null,
        "protocol_version": null,
        "thread_id": null,
        "warning_count": null
    },
    "result_id": {
        "current_field": null,
        "field_count": null,
        "lengths": null,
        "num_rows": null,
        "type": null
    },
    "result_array": [],
    "result_object": [],
    "custom_result_object": [],
    "current_row": 0,
    "num_rows": null,
    "row_data": null
}

使用这个

return $team_points->result();

而不是

return $team_points;

如果您需要一个数组作为结果:

return $team_points->result_array();

或者只是标准对象:

return $team_points->result();

另外,我认为你的sql说法有误。 你打算写:

ORDER BY matches.winner