{"action":"created","issue":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4131","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4131/labels{/name}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4131/comments","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4131/events","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4131","id":107568548,"number":4131,"title":"DB->query() returns 0 rows","user":{"login":"fluffypony","id":1944293,"avatar_url":"https://avatars.githubusercontent.com/u/1944293?v=3","gravatar_id":"","url":"https://api.github.com/users/fluffypony","html_url":"https://github.com/fluffypony","followers_url":"https://api.github.com/users/fluffypony/followers","following_url":"https://api.github.com/users/fluffypony/following{/other_user}","gists_url":"https://api.github.com/users/fluffypony/gists{/gist_id}","starred_url":"https://api.github.com/users/fluffypony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fluffypony/subscriptions","organizations_url":"https://api.github.com/users/fluffypony/orgs","repos_url":"https://api.github.com/users/fluffypony/repos","events_url":"https://api.github.com/users/fluffypony/events{/privacy}","received_events_url":"https://api.github.com/users/fluffypony/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":25,"created_at":"2015-09-21T18:15:07Z","updated_at":"2015-09-23T11:17:42Z","closed_at":null,"body":"I have a relatively complex SELECT statement that I run directly via ```$this->db->query($sql);```. For some reason this returns no rows. The way I'm checking the result is the advised way per the documentation:\r\n\r\n```\r\n\t\tif($query->num_rows() > 0)\r\n\t\t{\r\n\t\t\treturn $query->result();\r\n\t\t}\r\n```\r\n\r\nI've run the same query directly through mysqli using the following code, and it works and returns results as expected:\r\n\r\n```\r\n<?php\r\n\r\n$db = new mysqli('localhost', 'username', 'password', 'database');\r\n\r\n$sql = \"<statement goes here>\";\r\n\r\n$result = $db->query($sql);\r\n\r\necho var_dump($result);\r\necho var_dump($result->fetch_all());\r\n\r\nwhile ( $val = $result->fetch_object() )\r\n{\r\n\techo var_dump($val);\r\n}\r\n\r\n$result->close();\r\n$db->close();\r\n\r\n?>\r\n```\r\n\r\nObviously the query also runs fine directly in mysql.\r\n\r\nThis is what I've done to debug the issue thus far:\r\n\r\n1. Logged what $sql is before running the query, it is running the query that I expect\r\n2. Logged what $this->db->last_query() is after the $this->db->query() call, and it confirms that it ran the query completely unchanged.\r\n3. Turned the profiler on for the controller, confirmed that the query is there and it is the same query that I expect.\r\n4. Added \"EXPLAIN \" to the beginning of the SQL statement and logged the result, confirming that the correct explain is coming back.\r\n\r\nI've also confirmed that 1, 2, and 3 are all showing the same SQL query.\r\n\r\nI'm running 3.0.1 release, but am experiencing the same issue on 3.0.2-dev."},"comment":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/comments/142571475","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4131#issuecomment-142571475","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4131","id":142571475,"user":{"login":"narfbg","id":1058011,"avatar_url":"https://avatars.githubusercontent.com/u/1058011?v=3","gravatar_id":"","url":"https://api.github.com/users/narfbg","html_url":"https://github.com/narfbg","followers_url":"https://api.github.com/users/narfbg/followers","following_url":"https://api.github.com/users/narfbg/following{/other_user}","gists_url":"https://api.github.com/users/narfbg/gists{/gist_id}","starred_url":"https://api.github.com/users/narfbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narfbg/subscriptions","organizations_url":"https://api.github.com/users/narfbg/orgs","repos_url":"https://api.github.com/users/narfbg/repos","events_url":"https://api.github.com/users/narfbg/events{/privacy}","received_events_url":"https://api.github.com/users/narfbg/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T11:17:42Z","updated_at":"2015-09-23T11:17:42Z","body":"There's a difference in affected_rows this time for some reason ... but that may be due to the query in question being an UPDATE or something.\r\n\r\nHave you tried pulling results by running both CI and raw PHP under the same SAPI? I suspect that's where the actual difference comes from. FPM and CLI binaries are completely independent and a mix of different php.ini settings, DNS cache and permissions (because IIRC they are given on 'user'@'host' as opposed to just 'user') may be the issue."}}