Jonathan Tapicer wrote:
> Hi,
>
> I don't say that reading the whole file into memory is the best
> option, I just say that your approach goes to the disk twice, if you
> have a 100MB file, you are reading 200MB from disk (unless there are
> some pages cached in physical memory, but you never can
Hi,
I don't say that reading the whole file into memory is the best
option, I just say that your approach goes to the disk twice, if you
have a 100MB file, you are reading 200MB from disk (unless there are
some pages cached in physical memory, but you never can know, in the
best case all the pages
Hi,
> 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
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
or $arr = file('foo.csv'); $count = count($arr);
On Wed, Jun 24, 2009 at 5:19 PM, Richard Heyes 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)) {
>
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
To do the line count first, you have to read the whole file, how would
you do it?
On Wed, Jun 24, 2009 at 3:00 PM, Richard Heyes wrote:
> Hi,
>
>> 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 tw
Hi,
> 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.
Sure you can, simply do the line count first, then the i
Stuart wrote:
> 2009/6/24 Jonathan Tapicer :
>> 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
2009/6/24 Jonathan Tapicer :
> 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
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.
On Wed, Jun 24, 2009 at 11:12 AM, Richard Heyes wrote:
> Hi,
>
>> You
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 billi
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.
Jonathan
On Wed, Jun 24, 2009 a
On Fri, 10 Oct 2003 18:09:14 -0400, Dan Anderson <[EMAIL PROTECTED]>
wrote:
while ($line = mysql_fetch_array($result))
{
if ($first)
{ foreach ($line as $key => $value)
{ if ($first)
{ fwrite($file_handle, $key); $first = FALSE; }
else
{ fwrite($file_handle, ", $key"); }
}
fwrite ($file_handle
You could do something like:
$result = mysql_query($query) or die(mysql_error()); // don't display
errors on production machines
$first = TRUE;
while ($line = mysql_fetch_array($result))
{
if ($first)
{
foreach ($line as $key => $value)
{
if ($first)
{ fwrite($f
15 matches
Mail list logo