Hi guys I am trying to write simple program that extracts data from database using PDO, save it as multidimensional array and then convert it to XML.
The problem is that I cannot have numeric key that contains zero, because I am using Array2XML class for conversion and this class converts all keys to xml tags (and error tells me that tag with 0 inside is illegal).
So is there any way to extract data from database into multidimensional array and avoid getting 0 (I do not mind skipping using numeric keys at all)? Here is my code:
<?php
require 'config.php';
require 'array2xml.php';
//get username and password
$config = new Config();
$user = $config->getUser();
$pass = $config->getPass();
//create connection object
try {
$dbc = new PDO('mysql:host=localhost;dbname=StudentDB',
$user, $pass);
echo 'Connection established <br>';
}
catch(PDOException $e) {
echo "An error occured while connecting to database: "
. $e->getMessage();
}
$sql = $dbc->query('SELECT * FROM student');
$result = $sql->fetchALL(PDO::FETCH_CLASS);
echo "<pre>" . print_r($result, true) . "<pre/>";
echo "<br>";
echo "<br>";
//create object of class capable of conversion
$convert = new Array2XML();
$xml = $convert::createXML("Student", $result);
$xmlstring = $xml->saveXML();
echo "<pre>" . $xmlstring . "<pre/>";
I would like to seek your wisdom and ask for help. Thank you
Here is the proof that my question is different from:
PDO fetchAll group key-value pairs into assoc array
- In this question you are linking to he is not sure about his mysql query - he is not selecting entire table in raw format - and I am!
- His question has nothing to do with xml - NOTHING!
- If I am correct he is one step ahead of me so there is no way that solution for his problem wll work for me.