gpt4 book ai didi

php - 在 mysql 客户端中正确执行的查询在 PHP/CodeIgniter 中返回空结果

转载 作者:行者123 更新时间:2023-11-29 00:25:57 25 4
gpt4 key购买 nike

我一直在试图弄清楚为什么在 mysql 中有效的查询在 CodeIgniter 中无效。这是代码:

    $this->db->select('*');
$this->db->from('table');
$this->db->where('table.project_id', $project_id);
$this->db->where('table.user_id', $user_id);
$q = $this->db->get();
$result = $q->result();
log_message('error', 'error message='.$this->db->_error_message());
log_message('error', 'error number='.$this->db->_error_number());
log_message('error', 'result='.print_r($result, true));
log_message('error', 'last query='.$this->db->last_query());

日志输出如下所示:

ERROR - 2013-09-20 08:53:03 --> error message=
ERROR - 2013-09-20 08:53:03 --> error number=0
ERROR - 2013-09-20 08:53:03 --> result=Array
(
)

ERROR - 2013-09-20 08:53:03 --> last query=SELECT `table`.*
FROM (`table`)
WHERE `table`.`project_id` = '99'
AND `table`.`user_id` = '1927'

当我在 mysql 中运行查询时,我得到:

mysql> SELECT `table`.*
-> FROM (`table`)
-> WHERE `table`.`project_id` = '99'
-> AND `table`.`user_id` = '1927';
+------+---------+----------+------------+----------------+
| id | user_id | group_id | project_id | accepted_terms |
+------+---------+----------+------------+----------------+
| 2328 | 1927 | 8 | 99 | 0 |
+------+---------+----------+------------+----------------+
1 row in set (0.00 sec)

如您所见,CI 正在构建的查询是有效的,并且它在 mysql 客户端中返回了一个结果集。但是,查询在 CodeIgniter 中返回一个空数组。此页面上还有许多其他查询。我这辈子都想不通为什么这个查询在 CodeIgniter 中不起作用?

最佳答案

在您的 log_message 条目之后放入一个 die 语句,再次运行代码,看看您是否仍然看到手动运行查询时的结果。有可能您看到的代码是正确的,而其他地方正在插入数据。

关于php - 在 mysql 客户端中正确执行的查询在 PHP/CodeIgniter 中返回空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18918641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com