tags:

views:

82

answers:

2

I have a mysql query that runs in a php file that outputs a page of data. I need to somehow output that data to a file, to allow me to perform client side functions on that data as needed before exporting it for download.

I need the temporary file named as a timestamp. Im wondering if i should use the fopen to create the file with the name being something like echo date(), then fwrite = $mysql, then fclose?

Is this the correct way to do this?

+3  A: 

You could definitely do it that way. If it works for your purposes, then I would consider it correct. Sounds like you've got a good handle on it.

$filename = time() . '.txt';
$fp = fopen($filename,'w');
fputs($fp,$mysql);
fclose($fp);

If you want the filename with actual date numbering instead of a UNIX timestamp, use this instead:

$filename = date('YmdHis').'.txt';

You'll have to get your data into an exportable format of course... the code above assumes that $mysql contains your data and not just a query resource.

zombat
+2  A: 

The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. Read the documentaiton here...

http://dev.mysql.com/doc/refman/5.0/en/select.html

shantanuo