php - 如何从原始查询中获取 sql 结果
问题描述
在 codeIgniter 中获取 SQL 结果时出错。当我在 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_array();
或者只是标准对象:
return $team_points->result();
另外,我认为你的sql语句有错误。你打算写:
ORDER BY matches.winner
推荐阅读
- linux - linux命令行子文件夹文件批量重命名实际有效
- django - 当我在 android 设备上访问没有“www”的网站时,Apache2 显示默认页面,但使用“www”可以正常工作
- c++ - 如何使静态窗口在鼠标悬停时增加大小
- javascript - 获取用户视频流时,我的网络摄像头打开但视频流不显示
- curl - 通过 FTP 下载文件时遇到问题。(wget, curl, aria2c)
- asp.net - 如何诊断 Kubernetes Pod Launching 问题?
- git - 以编程方式从 GitHub 拉取请求中查找变更集
- python - 在 df.loc...str.extract() 上使用布尔索引会返回意外结果
- r - 合并或组合两个具有不相等行的数据框,并用 R 中 NA 的最接近值填充空白
- r - R:对数据框中的前 30 个组进行子集化