Page 1 of 1

PHP - odbc_exec only return one record - using access

Posted: Sat May 27, 2006 10:36 am
by Silverkeebs
Hey all.

So I am running into an interesting problem that I have only been so successful in resolving. I have written a complex query that is a combination of multiple loops and string concatinations, and when it is all said and done it is actually a query within a query, but I do not believe that is the issue.

Once I have the query built, I pass it into to the odbc_exec function as follows:

$cur = odbc_exec( $cnx, $selectStatement ); //where $cnx is an odbc_conenction to an access database, works fine

while( odbc_fetch_row( $cur ) )
{
$example_set = odbc_result( $cur, 1 ); //example of accessing the fields
echo $example_set;
}

For some reason this only prints out one record and then stops. Now, I also print out the select statement, which I copy into access and run as a query there, and it pulls up three records, so I know that it should be pulling three, but this only pulls 1.

I had this problem once before, and the solution was to copy and paste working code from another web page, and all of a sudden it worked... strangest thing. (know that there must be some reason behind that copy paste, but so far no luck on my part).

Additionally, if I write a simpler select statement, it does pull up multiple records, which makes me think that it is my big select statement. But as I stated above the select statement I am using works in access perfectly fine (the big one that is).

Are there any built in limitation on the odbc_exec or anywhere that might limit the number of records that are returned?

I am using the latest version of php on windows XP with IIS.

Thank you for you time

Re: PHP - odbc_exec only return one record - using access

Posted: Sat May 27, 2006 1:09 pm
by RobertGonzalez
Silverkeebs wrote:

Code: Select all

<?php
while( odbc_fetch_row( $cur ) )
{
   $example_set = odbc_result( $cur, 1 ); //example of accessing the fields
   echo $example_set;
}
?>
For some reason this only prints out one record and then stops. Now, I also print out the select statement, which I copy into access and run as a query there, and it pulls up three records, so I know that it should be pulling three, but this only pulls 1.
Try using using the odbc_fetch_array() function instead while reading the $cur result into an array ($row for example) then echoing out $row['fieldname']. See what that does.