-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.php
45 lines (37 loc) · 1.14 KB
/
xml.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
<?php
$br="<br />";
$sql = mysql_connect("localhost:3306","root","root");
if(!$sql)
{
die("Connect to mysql failed: ".mysql_error());
}
/*
$db = mysql_select_db($_POST["database"]);
if(!$db){
die("Open DB ".$_POST["database"]."failed,".mysql_error());
}
$result = mysql_query('select * from '.$_POST["table"].' order by personID');
*/
$db = mysql_select_db("phpDB");
if(!$db){
die("Open DB "."phpDB"."failed,".mysql_error());
}
$result = mysql_query('select * from '.'Persons'.' order by personID');
//echo 'select * from '.$_POST["table"].'order by Age'." ".mysql_error();
header('Content-type: application/xhtml+xml');
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$xml .= "<data>";
while($row = mysql_fetch_array($result))
{
$xml .= create_item($row['personID'],$row['FirstName'],$row['LastName'],$row['City'],$row['Age']);
}
$xml .= "</data>";
echo $xml;
function create_item($personID,$firstname,$lastname,$city,$age)
{
$item .= "<item>";
$item .= "<ID>".$personID."</ID>"."<FirstName>".$firstname."</FirstName>"."<LastName>".$lastname."</LastName>"."<City>".$city."</City>"."<Age>".$age."</Age>";
$item .= "</item>";
return $item;
}
?>