Save to a XML document using php problem
Hey all. I'm trying to save A XML file using php. here is my code, the connection to the DB is okay and all, i can use $dom->saveXML() but the save function isn't saving nothing. please help.
<?
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM Listing_Arnona WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("Price",$row['Price']);
$newnode->setAttribute("PriceS", $row['Price开发者_开发百科']);
$newnode->setAttribute("address", $row['street_name']);
$newnode->setAttribute("NumRooms", $row['Room_Num']);
$newnode->setAttribute("PROMO", $row['PROMO']);
}
$dom->formatOutput = true;
$test1 = $dom->saveXML(); // put string in test1
$dom->save('test1.xml'); // save as file
?>
The problem as everyone pointed out was the writing permissions. i opend a new folder name 'xml' with chmod 777 and changed the code to:
$dom->save('xml/test1.xml');
Thank you all.
精彩评论