Here i am trying to use XMLSerializer class to convert data from mysql table into an xml file.I want the xml file to be like this
For this ,i need to change the numeric indexes into 'book'.Currently i can generate an array of the following form:It has numeric indexing ,but for my purpose both of the indexes (0 and 1) have to be 'book'.
How can i change both the numeric indexes to be 'book'??
FULL CODE:
include('XMLSerializer/XML/Serializer.php');
$host='localhost';
$user='root';
$pass='';
$db='xmlserializer';
$dbh=new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$sql='SELECT lname,fname FROM employee';
$sth=$dbh->prepare($sql);
$sth->execute();
$xml=array('library'=>array());
$i=0;
while($result=$sth->fetch(PDO::FETCH_ASSOC)){
array_push($xml['library'],$result);
}
print_r($xml);
$serializer=new XML_Serializer();
$result=$serializer->serialize($xml);
if($result===true){
file_put_contents('myxml.xml',$serializer->getSerializedData());
}