Re: fputs() to save mysql db file

From: Date: Fri, 19 Jan 2001 18:11:06 +0000
Subject: Re: fputs() to save mysql db file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35675@lists.php.net to get a copy of this message
> I am trying to make a tab delimited file of a mysql table so I can open > it with Excel. > I select the data - 40 fields, 808 records no prob. > I view a mysql_num_rows() query to make sure it selects all records; no prob. > > I create a tab delimited format: > $result = mysql_query("SELECT * FROM $database"); > $rows=mysql_num_rows($result); > while ($row = mysql_fetch_array($result) ) > { > $field1="$row[field1]"; > $field2="$row[field2]"; file://etc.... > > $html.="$field1 $field2 $field3....." I'm assuming there are TAB characters in there?... Actually, though, you could save yourself some grief here and just do explode("\t", $row) to get your line to output. > } > > Then I write it to a file: > if (! ($myfile=fopen ("tables", "w"))) {echo "file could not be > opened";} > fputs ($myfile, "$html"); > fclose ($myfile); > > THE PROBLEM IS... > > The file that is written is missing about 400 records! > If I limit the fields to a few, I get all 808 records written no problem. > So, I imagine the problem is the file size - the 400 records equate to > about 131K. > Is there a problem using the fputs() function for larger files? There shouldn't be any problem. A few hundred K is just not that big. However, you could make this more efficient by opening the file when you do the query, and spitting out each line as you get it. I dunno what's going wrong, but you'll have a way better program, and maybe the gods will smile on you then and let it work. :-)

« previous php.general (#35675) next »