I need to turn an array into an XML file. I have the following code:
<?php
$nouser = 'There is no user with that ID in the database.';
try {
$handler = new PDO('sqlite:Ebsco.db');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$name = '';
if (isset ($_POST['postname'])) {
$name = $_POST['postname'];
};
$query = $handler->query('SELEcT * FROM Users WHERE ID='.$name);
$User = $query->fetch(PDO::FETCH_ASSOC);
if ($User) {
$Serializer = &new XML_Serializer();
$XML = $Serializer->serialize($User);
print_r($XML);
print_r($Serializer);
}
else {
echo $nouser;
}
}
catch (PDOException $e) {
echo $nouser;
die();
}
?>
The code works fine for retrieving the array and passing it back to the html as an array, but I am having issues with the PEAR XML_SERIALIZER. I have downloaded the files and placed them in the php/pear/xml folder (except for "package" which I left in the main pear folder, as I have no idea what it is meant to do), and checked the phpinfo() to make sure the include_path leads to php/pear. However, when I add the XML_SERIALIZER, I get the following error:
Fatal error: Class 'XML_Serializer' not found in...
I am new to PEAR so I'm not sure if I installed everything correctly (other than putting the files in the library, is there anything else I need to do?), or if this is caused by another issue. Thanx
You need to include the file manually, there is no autoloading with PEAR1 packages except you do that yourself.
require_once 'XML/Serializer.php';