I am stuck trying to figure out why a query that works in mysql does not work in CodeIgniter. Here's the code:
$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());
The log output on this looks like this:
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'
When I run the query in mysql I get:
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)
As you can see, the query that CI is constructing is valid, and it returns a result set in the mysql client. However, the query returns an empty Array in CodeIgniter. There are many, many other queries that are working on this page. I can't for the life of me figure out why this query isn't working in CodeIgniter?
$q = $this->db->query('SELECT * FROM table WHERE project_id = 99 AND user_id = 1927');Also, try to print_r($result);die(); before you do any logging and see if you still get no result.