Visualizzazione dei risultati da 1 a 2 su 2

Discussione: errore creazione XML

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    64

    errore creazione XML

    Ciao a tutti sto usando una classe php (che ho trovato in questo forum ) che consente di creare XML da un DB MYSQL
    posto il codice:


    <?

    try {
    $strn_dns='mysql:host=localhost;dbname=fru';
    $user="root";
    $pass="ARTEMY04";

    $db = new PDO($strn_dns ,$user, $pass);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
    $db->query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");
    } catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
    }



    class buildXml {
    private $db;
    private $tabella;
    private $dom;
    public function __construct(PDO $db, $tabella = '',$versione = '1.0', $charset = 'UTF-8') {
    $this->db = $db;
    if ($tabella == '') {
    throw new Exception('Devi indicare quale tabella vuoi aggiornare!!');
    }
    $this->tabella = $tabella;
    $this->dom = new DOMDocument($versione, $charset);
    $this->creaXml();
    }

    private function __eseguiQuery() {
    $rows= array();
    foreach($this->db->query("SELECT * FROM ".$this->tabella) as $row){
    $rows[]= $row;
    }
    return $rows;
    }
    private function creaXml() {
    $rows= $this->__eseguiQuery();
    $domRoot= $this->dom->createElement($this->tabella);
    $this->dom->appendChild($domRoot);
    foreach ($rows as $row) {
    $item= $this->dom->createElement('item');
    foreach ($row as $key => $value){
    if(is_string($key)){
    $node= $this->dom->createElement($key);
    $text= $this->dom->createTextNode($value);
    $node->appendChild($text);
    $item->appendChild($node);
    }
    }
    $domRoot->appendChild($item);
    }
    }
    public function showXml(){
    header('Content-Type: text/xml');
    //ritorno il documento xml corretto
    echo $this->dom->saveXML();
    }
    public function save($fileName){
    $this->dom->save($fileName);
    }
    }
    $o= new buildXml($db,'evento');
    //$o->showXml();
    $o->save('pippo.xml');

    ?>


    mi da un errore quando tenta di modificare l' header perche nella pagina html gia l'header lo da...
    coem posso risolvere?

    Grazie in anticipo

  2. #2

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.