views:

235

answers:

1

I'm using UnixODBC with PHP 5.2.4 on Ubuntu 8.04 LTS and trying to pull all the results from a table sitting on an iSeries and replicate them to a local MySQL table.

Code-wise it is working with no errors but I'm ending up with more rows that what is contained on the iSeries.

I should end up with 25,613 rows but PHP reports that 25,630 rows are being inserted into the MySQL database:

$counter = 0;
while($row = odbc_fetch_array($result)) {
    //Insert into MySQL using Zend Framework
    $counter++;
}
echo $counter;

When I look in the MySQL database some of the rows are actually duplicated. I saw a note on the odbc_fetch_array() documentation about erratic behavior when accessing the iSeries, but trying that solution causes the script to run and run without ever seeming to finish.

Any ideas on what to check?

A: 

Is it the same rows being duplicated each time? If so, is there anything unique about these records that could hint on why they are duplicated?

Perhaps use another binding for getting results -- like odbc_fetch_row(). What does odbc_num_rows() say?

These and other techniques might help you zone in on the bug.

ashawley
odbc_num_rows() returns '-1' and doing odbc_fetch_row() with a counter returns 25,630.
dragonmantank
While I'm not sure why odbc_num_rows() isn't working right, I found out that the MySQL table wasn't getting truncated and causing the duplicate rows. Everything seems to be syncing up now correctly after switching to odbc_fetc_row().
dragonmantank