• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$query->num_rows(); can not get the number of rows

I retrieve the records Ifm ODBC / Access database 2007
it works
$this->db->where('EMAIL', $strSearch);
$data['query']= $this->db->get('MYTABLE');

I can list the records all OK.
in view file
echo $query->num_rows();
gives -1 result

What is wrong?

Having a quick look at the ODBC driver, it just returns the value of odbc_num_rows which is a PHP function
That function returns -1 on error, so its a PHP/ODBC fault, not a CI problem

Are you getting anything in your error logs? (Make sure you have logging enabled)

yes, I hv enabled the logs at 4 level
No error with database.
the result is -1 even though there are records returned from query.

I recently ran into this same problem using an Access database. If you look into the CI library /system/database/drivers/odbc_result.php, the function num_rows() is null. The function is commented that ODBC does not support it. I used the following query.
//Query DB for number of rows in result
$rows_query = $this->db->query('SELECT Count(CUSTOMER.CUSTOMERKEY) AS Count

//Result saved as an array        
$rows = $rows_query->row_array();

echo $rows['Count'];

Why are you calling $query->num_rows();

You are using an ActiveRecord call that returns an array. You have no object to call num_rows() against.

If you want to continue to use ActiveRecord you need to call:

Basically, you are mixing ActiveRecord functions with the database class functions

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.