Welcome Guest, Not a member yet? Register   Sign In
$query->num_rows(); can not get the number of rows
#1

[eluser]test2009[/eluser]
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.
But
in view file
echo $query->num_rows();
gives -1 result

What is wrong?
#2

[eluser]Dam1an[/eluser]
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)
#3

[eluser]test2009[/eluser]
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.
#4

[eluser]pickupman[/eluser]
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.
Code:
//Query DB for number of rows in result
$rows_query = $this->db->query('SELECT Count(CUSTOMER.CUSTOMERKEY) AS Count
FROM CUSTOMER');

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

echo $rows['Count'];
#5

[eluser]Jondolar[/eluser]
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:
$this->db->count_all('my_table');

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




Theme © iAndrew 2016 - Forum software by © MyBB