1

I need to generate a XML file from a Database, I wrote this PHP code, but it's showing nothing. I first thought the problem was because of a bad connection/query, but that's not the problem. They are both working fine.

I think the problem is the "mysql_fetch_assoc($result)", but I'm not sure because can't really fix it!

<?php
$con = new mysqli('localhost', 'root', 'usbw', 'bierdb', 3307);

$query = "SELECT biernaam, kleur FROM bier";
$result = $con ->query($query);

$xml = new XMLWriter();

$xml->openURI("bieren.xml");
$xml->startDocument();
$xml->setIndent(true);

$xml->startElement('kaart');

if(is_resource($result)) {

    while ($row = mysql_fetch_assoc($result)) {
        $xml->startElement("Bier");

        $xml->writeAttribute('kleur', $row['kleur']);
        $xml->writeRaw($row['biernaam']);

        $xml->endElement();
    }

    $xml->endElement();

    header("Content-Type:text/xml");
    echo $xml->flush();
}
?>

Thanks for reading and helping me, I appreciate it!

NoOtaku
  • 21
  • 1
  • 4
  • When you develop you should enable error reporting otherwise you will look for causes in the wrong places when you run into problems: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456) --- hint: `is_resource($result)` will always return `FALSE` in your code. It's sufficient you make a boolean check like `if ($result) { ...` and then instead of `while` just do a `foreach($result as $row) { ...` and you should be fine. See http://php.net/manual/en/class.mysqli-result.php - For foreach you need PHP 5.4+ which you hopefully have. – hakre Apr 28 '15 at 17:29

0 Answers0