urlLoader XML

I have the following php file that generates an xml from a sql_query:

<?php

include("php/dbconnect.php"); //connects to the database
//sql_query
$table_id = 'booking';     
$query = "SELECT * FROM $table_id WHERE (booking.bookingDate = curDate()) AND roomID = 1 ORDER BY startTime";
$room1 = mysql_query($query);
                        
                        
//create a new DOM document
$doc = new DOMDocument('1.0');
                        
//create root element
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
                        
//process one row at at time 
while($row = mysql_fetch_assoc($room1)){
                            
//add node for each row
$occ = $doc->createElement($table_id);
$occ = $root->appendChild($occ);
                        
//add achild for each field
foreach ($row as $fieldname => $fieldvalue){
                            
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);

                        
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
                        
$xml_string = $doc->saveXML();
                       
echo $xml_string;
                        
mysql_free_result($room1);
?>

Is this the right way to generate xml from a sql_query that will be taken into AS3 as I do not want the xml to print to the screen I want it to be taken into AS3?