-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnew.php
75 lines (64 loc) · 2.7 KB
/
new.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
64
65
66
67
68
69
70
71
72
73
74
75
<?php
//include("C:\xampp\htdocs\phpfiles\index.php");
require("phpsqlajax_dbinfo.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("gases");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
/*$sql ="UPDATE gases SET CO=RAND()*100,NO=RAND()*100,NO2=RAND()*100,O3=RAND()*100,FineParticles=RAND()*100,CourseParticles=RAND()*100 WHERE id=1";
$sql= "UPDATE gases SET CO=RAND()*100,NO=RAND()*100,NO2=RAND()*100,O3=RAND()*100,FineParticles=RAND()*100,CourseParticles=RAND()*100 WHERE id=2";
$sql= "UPDATE gases SET CO=RAND()*100,NO=RAND()*100,NO2=RAND()*100,O3=RAND()*100,FineParticles=RAND()*100,CourseParticles=RAND()*100 WHERE id=3";
*/
/*$query = "SELECT * FROM gases WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// Add to XML document node
$node = $dom->createElement("gas");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("CO",$row['CO']);
$newnode->setAttribute("NO", $row['NO']);
$newnode->setAttribute("NO2", $row['NO2']);
$newnode->setAttribute("O3", $row['O3']);
$newnode->setAttribute("FineParticles", $row['FineParticles']);
$newnode->setAttribute("CourseParticles", $row['CourseParticles']);
}
echo $dom->saveXML();*/
function toXML(){
$data_txt=null;
$myFile = "myxml.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
$data_txt .= '<?xml version="1.0" encoding="utf-8"?>';
$data_txt .= '<gases>';
$query = mysql_query("SELECT * FROM gases");
while($values_query = mysql_fetch_assoc($query))
{
$data_txt .= '<gas>';
$data_txt .= '<CO>' .$values_query['CO']. '</CO>';
$data_txt .= '<NO>' .$values_query['NO']. '</NO>';
$data_txt .= '<NO2>' .$values_query['NO2']. '</NO2>';
$data_txt .= '<O3>' .$values_query['O3']. '</O3>';
$data_txt .= '<FineParticles>' .$values_query['FineParticles']. '</FineParticles>';
$data_txt .= '<CourseParticles>' .$values_query['CourseParticles']. '</CourseParticles>';
$data_txt .= '<lat>' .$values_query['lat']. '</lat>';
$data_txt .= '<lng>' .$values_query['lng']. '</lng>';
$data_txt .= '<type>' .$values_query['type']. '</type>';
$data_txt .= '</gas>';
}
$data_txt .= '</gases>';
fwrite($fh, $data_txt);
fclose($fh);
}
?>