ms and odbc - only returns half the rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skeleton Man

    ms and odbc - only returns half the rows

    Hi,

    I'm attempting to fetch all the data from an MS Access database, but every
    time I try with any query it only returns every second row..

    I could rows numbered from 1 to 4000 and it would return exactly 2000 rows..
    I would get rows 2, 4, 6, 8, 10 ,etc..

    This is the code I am using:

    $dsn = "DRIVER=Microso ft Access Driver (*.mdb); DBQ=c:\\mdb\\da ta.mdb;";
    $myDB = odbc_connect($d sn,'Admin','') or die (odbc_error());

    $query = 'SELECT * FROM Hist_data';
    $result = odbc_exec($myDB , $query);
    $output = array();

    while (odbc_fetch_row ($result)){
    $output[] = odbc_fetch_arra y($result);
    }

    print "Results of your query:\n\n";
    print_r($output );

    I tried firing up MS access and running exactly the same query, but that
    functions normally and returns all the rows, so I'm assuming this is a PHP
    bug..

    Chris


  • Hendri Kurniawan

    #2
    Re: ms and odbc - only returns half the rows

    See below:



    Skeleton Man wrote:
    Hi,
    >
    I'm attempting to fetch all the data from an MS Access database, but every
    time I try with any query it only returns every second row..
    >
    I could rows numbered from 1 to 4000 and it would return exactly 2000 rows..
    I would get rows 2, 4, 6, 8, 10 ,etc..
    >
    This is the code I am using:
    >
    $dsn = "DRIVER=Microso ft Access Driver (*.mdb); DBQ=c:\\mdb\\da ta.mdb;";
    $myDB = odbc_connect($d sn,'Admin','') or die (odbc_error());
    >
    $query = 'SELECT * FROM Hist_data';
    $result = odbc_exec($myDB , $query);
    $output = array();
    >
    ------------------------------------------------------
    while (odbc_fetch_row ($result)){
    $output[] = odbc_fetch_arra y($result);
    }
    --------------------------------------------------------
    This is the offending code. Your code fetches the result twice.
    you should write something like:

    while($temp = odbc_fetch_arra y($result)) $output[] = $temp;


    >
    print "Results of your query:\n\n";
    print_r($output );
    >
    I tried firing up MS access and running exactly the same query, but that
    functions normally and returns all the rows, so I'm assuming this is a PHP
    bug..
    >
    Chris
    >
    >

    Comment

    • Skeleton Man

      #3
      Re: ms and odbc - only returns half the rows

      >------------------------------------------------------
      >while (odbc_fetch_row ($result)){
      > $output[] = odbc_fetch_arra y($result);
      >}
      >--------------------------------------------------------
      >This is the offending code. Your code fetches the result twice.
      >you should write something like:
      >while($temp = odbc_fetch_arra y($result)) $output[] = $temp;
      Thanks, must've been a brain fart I think ;-)

      Chris


      Comment

      Working...