# Scripting Database entries into XML

**URL:** <https://forum.kirupa.com/t/scripting-database-entries-into-xml/301342>\
**Category:** programming\
**Created:** [December 8, 2009, 12:08am UTC](https://forum.kirupa.com/t/scripting-database-entries-into-xml/301342 "2009-12-08T00:08:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaughDonor](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@LaughDonor](https://forum.kirupa.com/u/LaughDonor)\
**Post date:** [December 8, 2009, 12:08am UTC](https://forum.kirupa.com/t/scripting-database-entries-into-xml/301342/1 "2009-12-08T00:08:28Z")

</div>

Just wanted to say that I enjoyed [Jubba’s guide for converting [URL=“http://www.kirupa.com/web/mysql\_xml\_php.htm”]database entries into XML](http://www.kirupa.com/forum/member.php?u=5)… I wanted to show you guys my version from where I tweaked his ideas from it.

```php
$query = "SELECT * FROM members";
$resultID = mysql_query( $query ) or die ( 'Error: ' . mysql_error () );

function member2xml( $param, $type, &$xml ) {
	if( !is_numeric($type) )
		$xml .= " <" . str_replace( " ", "", $type ) . ">" . htmlspecialchars($param, ENT_QUOTES) . "</" . str_replace( " ", "", $type ) . ">
";
}
	
$xml = "<?xml version=\"1.0\"?>
";
$xml .= "<contacts>
"; 

while( $r = mysql_fetch_array( $resultID ) ) {
    $xml .= "	<person>
"; 
	array_walk( $r, "dish2xml", &$xml );
    $xml .= "	</person>
"; 
}

$xml .= "</contacts>";

```

I was using it for a cookbook, but just changed names around to a contactlist of a sort… but you get the idea! I just wanted to share it… and if anyone wants to reshare it, awesomeness!
