Page 1 of 1
odbc_num_rows() with MS Access always gives -1
Posted: Thu Jul 29, 2004 11:24 am
by Chris Corbyn
Hi,
I'm trying to count the number of row in a Microsft Access database I've got.
I'm doing ti like this
Code: Select all
$user_odbc = "user";
$pass_odbc = "pass";
$database_odbc = "clientsDB";
$connect_db = odbc_connect($database_odbc,$user_odbc,$pass_odbc) or die ('Wrong Connect Details');
$query = "SELECT * FROM websites";
$result_odbc = odbc_exec($connect_db,$query);
$odbc_num_rows = odbc_num_rows($result_odbc);
echo $odbc_num_rows;
And no matter how many rows are in my table I always get the output as -1. Can I do this a more reliable way?
Thanks
Posted: Thu Jul 29, 2004 1:32 pm
by Weirdan
Posted: Thu Jul 29, 2004 1:40 pm
by Chris Corbyn
Still returns -1. I've been Googling for this for hours. All the PHP manual has to say is
Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.
But if I don't use select to pull out my rows what else can I use?
The only thing I'm thinking is that I can read the highest value of the primary key and take that as the number of rows but it's a bit of botch-up.
Posted: Thu Jul 29, 2004 1:51 pm
by feyd
not sure if this will work through ODBC but:
Code: Select all
SHOW TABLE STATUS LIKE 'table_name'
should have the auto_increment's next value in it..
Posted: Thu Jul 29, 2004 2:01 pm
by Chris Corbyn
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'., SQL state 37000 in SQLExecDirect in d:\inetpub\wwwroot\add.php on line 13
Looks like the only queries I can make in ODBC with the Microsoft Access Driver are those shown above
Posted: Thu Jul 29, 2004 2:31 pm
by Chris Corbyn
Who thinks doing it like this is just a bit silly? It works though...
Code: Select all
$user_odbc = "user";
$pass_odbc = "pass";
$database_odbc = "clientsDB";
$connect_db = odbc_connect($database_odbc,$user_odbc,$pass_odbc) or die ('Wrong Command!!!');
$query = "SELECT * FROM websites";
$result_odbc = odbc_exec($connect_db,$query);
$i = 0;
while (odbc_fetch_row($result_odbc)) {
++$i;
}
odbc_close($connect_db);
echo 'The number of rows in Table "websites" is '.$i;
It probably wont work faultlessly no doubt although I see no reason why not....
Posted: Thu Jul 29, 2004 2:32 pm
by feyd
since it works, and you can't use any of the other systems, then that's the way to go I guess.
