0
I need to generate XML from a Mysql database. I’m using Mysql database with PHP (let’s be clear that I’m new to PHP, what I did was with a Youtube video (that) and very little of what I know).
<?php
define('HOSTNAME', '127.0.0.1');
define('USERNAME', 'root');
define('PASSWORD', null);
define('DATABASE', 'cadastro');
define('CHARSET' , 'utf8');
include_once("conexao.php");
$sql = 'select id, descricao, margem, custo, estoque from produtos';
$resultado = mysqli_query(DBConnect(), $sql) or die (mysqli_error(DBConnect()));
$xml = new DOMDocument('1.0', 'ISO-8859-1');
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$produtos = $xml->createElement=('Produtos');
while($dados = mysqli_fetch_object($resultado))
{
$item = $xml->createElement('Item');
$descricao = $xml->createElement('descricao', $dados->descricao);
$margem = $xml->createElement('margem', $dados->margem);
$custo = $xml->createElement('custo', $dados->custo);
$estoque = $xml->createElement('estoque', $dados->estoque);
$item->appendChild($descricao);
$item->appendChild($margem);
$item->appendChild($custo);
$item->appendChild($estoque);
$produtos->appendChild($item);
}
$xml->appendChild($produtos);
header('content-type: text/xml');
print $xml->saveXML();
?>
The error that gives:
Fatal error: Uncaught Error: Call to a Member Function appendchild() on string in C: xampp htdocs php_fundamental 2.Phpparaxml config.php:35 Stack trace: #0 {main} thrown in C: xampp htdocs php_fundamental 2.Phppaml raxconfig.php on line 35
(The line 35 that is said in error is rightly: $produtos->appendChild($item);
)
I’d like help finishing.