forked from geek09rk/trustdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryEffProtein.php
executable file
·63 lines (42 loc) · 1.62 KB
/
queryEffProtein.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
// Start the session
ini_set('display_errors', 1);
error_reporting(1);
require("config.php");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
// The request is a pre-flight request
// Send appropriate CORS headers and exit
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
exit;
}
// Set headers to allow all origins
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');
$species= $_POST['species'];
$namer= $_POST['namer'];
$outfile = "tmp/".$namer."_OutputQuery.txt";
$link = mysqli_connect('localhost:3306', DB_USER, DB_PASSWORD) or die('Could not connect to mysql');
$link->set_charset("utf8");
mysqli_select_db($link,'trustdb') or die('Could not select database');
$query = 'SELECT * FROM eff_proteins WHERE species="'.$species.'"';
// print_r($query);
$result = mysqli_query($link,$query) or die('Query failed: ' . mysqli_error($link));
$tabularFile = fopen($outfile, "w") or die("Unable to open file!");
while ($lineQueryResult = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$accessions = $lineQueryResult['accessions'];
$description = $lineQueryResult['description'];
$length = $lineQueryResult['length'];
$line = $accessions ."\t". $description ."\t". $length;
print_r($line);
print_r('\n');
fwrite($tabularFile, $line);
fwrite($tabularFile, PHP_EOL);
}
mysqli_free_result($result);
mysqli_close($link);
fclose($tabularFile);
print_r($namer);
?>