Re: CSV file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, you are reading the whole file there (and throwing the data you
read not assigning the fgets result to anything), and then to store it
in the database you need to read it again, so you read the file twice.
It will probably better to store the data you read the first time in
an array and then store it in the database, that way you read it only
once.

Anyway, doing it by file size is better.

On Wed, Jun 24, 2009 at 6:19 PM, Richard Heyes<richard@xxxxxxx> wrote:
> Hi,
>
>> To do the line count first, you have to read the whole file, how would
>> you do it?
>
> Something like this:
>
> $fp = fopen('/tmp/foo', 'r');
> $count = 0;
>
> while (!feof($fp)) {
>  fgets($fp);
>  ++$count;
> }
>
> --
> Richard Heyes
> HTML5 graphing: RGraph (www.rgraph.net - updated 20th June)
> PHP mail: RMail (www.phpguru.org/rmail)
> PHP datagrid: RGrid (www.phpguru.org/rgrid)
> PHP Template: RTemplate (www.phpguru.org/rtemplate)
> PHP SMTP: http://www.phpguru.org/smtp
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux