F
fikru
Guest
I would like to download query result from mysql table and save it as a FASTA file. Can this be done from DaDaBIK? Here is the code that I am interested in using:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=sequences.seq");
if(preg_match("/mac/i", $_SERVER['HTTP_USER_AGENT']))
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
}
$sesid = $_GET["ses"];
$sql = "SELECT * FROM my_table$sesid";
$link = mysql_connect ("localhost", "", "")
or die ("Could not connect");
mysql_select_db("my_db");
$result = mysql_query ($sql)
or die ("Could not execute query");
$numFields = mysql_num_fields($result);
while ($row = mysql_fetch_row($result))
{
$name=$row[3];
$uni=$row[1];
$ref=$row[2];
$seq = $row[29];
$size = strlen(trim($seq));
$seq=chunk_split($seq, 50, "\n");
$FASTA=sprintf(">%s|%s|%s|%sbp\n%s", $name,$uni,$ref,$size,trim($seq));
echo $FASTA;
echo "\n";
}
mysql_close($link);
?>
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=sequences.seq");
if(preg_match("/mac/i", $_SERVER['HTTP_USER_AGENT']))
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
}
$sesid = $_GET["ses"];
$sql = "SELECT * FROM my_table$sesid";
$link = mysql_connect ("localhost", "", "")
or die ("Could not connect");
mysql_select_db("my_db");
$result = mysql_query ($sql)
or die ("Could not execute query");
$numFields = mysql_num_fields($result);
while ($row = mysql_fetch_row($result))
{
$name=$row[3];
$uni=$row[1];
$ref=$row[2];
$seq = $row[29];
$size = strlen(trim($seq));
$seq=chunk_split($seq, 50, "\n");
$FASTA=sprintf(">%s|%s|%s|%sbp\n%s", $name,$uni,$ref,$size,trim($seq));
echo $FASTA;
echo "\n";
}
mysql_close($link);
?>