trg_dk
asked on
Convert MSSQL_query result to xml
Hi all
I'm looking for a function that will convert a MSSQL_query to XML. So far with no luck.
Either I could make an associative array and convert to xml - but so far also that fails - OR find a function that would convert a native MSSQL object to XML.
$res = mssql_query( $sql );
while($r = mssql_fetch_assoc( $res ) )
{
$t[] = $r;
}
header ("content-type: text/xml");
echo toXml( $t );
Any ideas or code ??
I'm looking for a function that will convert a MSSQL_query to XML. So far with no luck.
Either I could make an associative array and convert to xml - but so far also that fails - OR find a function that would convert a native MSSQL object to XML.
$res = mssql_query( $sql );
while($r = mssql_fetch_assoc( $res ) )
{
$t[] = $r;
}
header ("content-type: text/xml");
echo toXml( $t );
Any ideas or code ??
Damn pasting stripped out some "'s and things!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmmmm - I'd be very much PRO a function that I could use, as I would be using this for several functions
ach... still missed some on line 37 and 27... I'm sure you can work it out :)
ASKER
I found this function which works perfectly for me.
http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/
Points given for the effort :-)
http://www.sean-barton.co.uk/2009/03/turning-an-array-or-object-into-xml-using-php/
Points given for the effort :-)
should't be too hard to shove it into a function and use them in the select & loop... if you can't give me a shout and will do it tonight for ya.
make a function with a param say $data
a loop like this should build the select with the required cols... and then use a loop similarly within the recordset for loop to read the wanted columns...
foreach($data as $key=>$val) {
if(strtolower($val)=='null ') $q.= "`$key` = NULL, ";
elseif(strtolower($val)==' now()') $q.= "`$key` = NOW(), ";
else $q.= "`$key`='".$val."', ";
}
make a function with a param say $data
a loop like this should build the select with the required cols... and then use a loop similarly within the recordset for loop to read the wanted columns...
foreach($data as $key=>$val) {
if(strtolower($val)=='null
elseif(strtolower($val)=='
else $q.= "`$key`='".$val."', ";
}
Open in new window