Welcome Guest, Not a member yet? Register   Sign In
num_rows() returns -1 even when there are rows
#1

[eluser]whirled[/eluser]
Hi,

I am querying a MS Access database for a login controller, and was testing for the record count using the num_rows() method. I kept getting an error saying no records were returned from my code based on the number returned, and after echoing out the result of num_rows() I noticed that it was always -1, even when print_r($query->result_array()) displays the data that was returned.

Is this just a limitation of querying an Access database?

Thanks,

William
#2

[eluser]InsiteFX[/eluser]
What database driver are you using? For access I think you need to use the odbc driver.

InsiteFX
#3

[eluser]whirled[/eluser]
Hi,
The ODBC driver is being used. Also, in case this helps, the site is running on a Windows 2003 server using Zend Server CE with Apache. The MS Access DB is 2007.

The connection works fine, and I am able to read records using the active record methods, but num_rows() always returns -1.


The contents of my database.php file:
Code:
$db['default']['hostname'] = 'ZendServer_MSAccess_Database';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


The code from my model:
Code:
$query = $this->db->get_where('UsersTable', array('Emails' => $email));


Result of num_rows() and print_r of result_array():
Code:
-1

Array ( [0] => Array ( [UserID] => 8 [UserNumber] => 8 [UserFirstName] => Brian [UserLastName] => Something [Title] => Account Executive [Emails] => [email protected] [Pwd] => 1234 ) )

Thanks for the help.

-William
#4

[eluser]InsiteFX[/eluser]
How are you calling num_rows() ?

InsiteFX
#5

[eluser]whirled[/eluser]
Query is:
Code:
$query = $this->db->get_where('UsersTable', array('Emails' => $email));

Checking by using:
Code:
$query->num_rows();

I also tried using
Code:
$query = $this->db->query("Select * from UsersTable");

num_rows() still returns -1, even though data is retrieved.

Thanks,

-William
#6

[eluser]InsiteFX[/eluser]
num_rows() should either return 0 or the number of rows it found not -1

This could be a bug so you would have to report it to the CodeIgniter Reactor Team!

CodeIgniter Reactor - Issues

Ok, I just did some checking and found this out!
Code:
// odbc_num_rows for access does return -1. I use

count($resultset);

// it seams to work.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB