PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
header("Content-type: text/xml");
$myServer = "MYSERVER\SQLEXPRESS";
$myUser = "sa";
$myPass = "MYPW";
$myDB = "cars";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT id, type, year ";
$query .= "FROM cars";
//execute the SQL query and return records
$result = mssql_query($query);
//display the results
while($row = mssql_fetch_array($result))
{
$yearrow = $row['year'];
$typerow = $row['type'];
echo "<note>";
echo "<from>$yearrow</from>";
echo "<to>$typerow</to>";
echo "</note>";
}
//close the connection
mssql_close($dbhandle);
?>
The Data come out correctly but i get the Error "Only one top level element is allowed in an XML document. Error processing resource" and "Only one top level element is allowed in an XML document. Error processing resource"