Re: CSV file
| From: | Stuart | Date: | Wed, 24 Jun 2009 14:23:20 +0000 |
| Subject: | Re: CSV file | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294526@lists.php.net to get a copy of this message | ||
2009/6/24 Jonathan Tapicer <tapicer@gmail.com>:
> If you want to know how many lines there are *before* inserting to the
> database, you can't count "as you go", you have to either read the
> file twice or read it once, store it memory in a variable and then
> insert in the database.
Do it in bytes rather than lines, then you don't waste time loading
the file twice and you'll get the same end result.
-Stuart
--
http://stut.net/
> On Wed, Jun 24, 2009 at 11:12 AM, Richard Heyes<richard@php.net> wrote:
>> Hi,
>>
>>> You can read the whole file (file_get_contents) and count the number
>>> of "\n" in it, or read it line by line with fgets and store the lines
>>> in an array, and then the number of lines is the count() of the array,
>>> and you can use that array to store it in the database.
>>
>> If you have a billion line CSV then speed may suffer somewhat though.
>> Best to still use fgets() or fgetcsv() and count as you go.
>>
>> --
>> 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
>
>