<?php

	//grant file on *.* to qb@localhost identified by 'qb';
	ini_set('max_execution_time', 0);
	require_once 'auth.php';
	#$tmpfname = tempnam("/tmp", "outfile.txt");
	#if (file_exists($tmpfname)) unlink($tmpfname);

	#$adodb->Execute("SELECT * FROM ".$_GET['tableid'].
	#" INTO OUTFILE '".$tmpfname."' ".
	#" FIELDS TERMINATED BY ',' ".
	#" ENCLOSED BY '\"' ".
	#" LINES TERMINATED BY '\\n'");
	#echo $tmpfname;	
	#readfile($tmpfname);
	#unlink($tmpfname);
	if (!$_GET['tableid']) die('Emtpy Table');
	$rs = $adodb->Execute("SELECT * FROM ".$_GET['tableid']);
	if (!$rs) die($adodb->ErrorMsg());
	header("Content-type: text/comma-separated-values");
	header("Content-Disposition: attachment; filename=".$_GET['tableid'].".csv");
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
	header("Pragma: public");
	while (!$rs->EOF) {
		echo "\"".implode("\",\"", $rs->fields)."\"\n";
		$rs->MoveNext();
	}

?>