CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

query->result() returns empty

Open li9ht opened this issue 14 years ago • 10 comments

$query->result() is returning array{0} while $query->result_array() is returning correct result . driver odbc database informix

li9ht avatar Mar 05 '12 06:03 li9ht

because of this fix https://github.com/EllisLab/CodeIgniter/issues/129 when using query->result() in my code result return 0 but when

public function num_rows()
{
    if (is_int($this->num_rows))
    {
        return $this->num_rows;
    }

    // Work-around for ODBC subdrivers that don't support num_rows()
//  if (($this->num_rows = @odbc_num_rows($this->result_id)) === -1)
//  {
//      $this->num_rows = count($this->result_array());
//  }

    return @odbc_num_rows($this->result_id);
}

result will return correct value and result_array will return correct value; num_rows still will return -1

i think this issue https://github.com/EllisLab/CodeIgniter/issues/129 should be reopen priority is to get the result.. num rows can be count after getting the result in controller of model

li9ht avatar Mar 05 '12 07:03 li9ht

Sorry about that ... if we override the result_array() method with one that doesn't depend on num_rows(), it should be fine. Here's it is: https://github.com/EllisLab/CodeIgniter/commit/cc5af53346397846f2035dc2bf6a2c2f9b0cd4ab

I've tested it, but will leave this one open until you confirm.

narfbg avatar Mar 05 '12 12:03 narfbg

i did several test.. $query->result() still return empty array ..

li9ht avatar Mar 06 '12 02:03 li9ht

... _data_seek() sucks, here's another one: https://github.com/EllisLab/CodeIgniter/commit/9c68c3173c84041b1ee77929e540a4a4382edeee

narfbg avatar Mar 06 '12 08:03 narfbg

nice.. everything works fine now.. result() , result_array(), and num_rows() is returning the correct value.

li9ht avatar Mar 06 '12 08:03 li9ht

OK, closing this one then. :)

narfbg avatar Mar 06 '12 08:03 narfbg

version: CodeIgniter 2.1.3 num_rows() return is 60+ , but $query->result() and $query->result_array() is both return empty .... please help me ~~~

whyb avatar Jan 30 '13 08:01 whyb

I met the same error with whyb. $query->num_rows() return 19605 but $query->result_array() does not return anything. There are no errors found. 19605 records is not very large data, is it right? Please help.

tthanhlong avatar Jun 11 '15 07:06 tthanhlong

@tthanhlong , my database driver is odbc, ms sql server, But I met the problem two year ago. I not sure the new version was resolved it?

whyb avatar Jun 12 '15 01:06 whyb

Memory limit caused this problem. Default is 128M, but we can set memory_limit = 1024M or higher and you should be good.

ini_set('memory_limit', "1024M");

We also set unlimited by:

ini_set('memory_limit', "-1");

but it isn't be encouraged due to memory leak somewhere and out of control.

I changed to appropriate number and it seems to be fix.

Regards!

tthanhlong avatar Jun 12 '15 02:06 tthanhlong