PHP Version 4.3.9 on linux
I’m not a php guru but I’ve modified a bit of php code to populate MySql tables from a pipe separated flat file. It works ok but won’t come out of a ‘while’ loop.
Code fragment below. dbwrite() is a function (not included here) which updates the database. The database gets updates ok but it doesn’t come out of the loop at eof. If I take out the dbwrite() function call and run the program it exits out of the loop ok.
Any ideas welcome.
Thanks,
Dave
I’m not a php guru but I’ve modified a bit of php code to populate MySql tables from a pipe separated flat file. It works ok but won’t come out of a ‘while’ loop.
Code fragment below. dbwrite() is a function (not included here) which updates the database. The database gets updates ok but it doesn’t come out of the loop at eof. If I take out the dbwrite() function call and run the program it exits out of the loop ok.
Code:
#!/usr/local/bin/php -q
<?php
$file="/home/system/extract.txt";
if (file_exists($file)){
$handle=fopen($file,"r");
} else die();
while (!feof($handle)) {
$line=fgets($handle);
$data=explode('|', $line);
dbwrite($data);
}
fclose($handle);
?>
Thanks,
Dave