PHP Classes
Icontem

File: class.mysql_xml.phtml


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ricardo Costa  >  MySQL to XML - XML to MySQL  >  class.mysql_xml.phtml  
File: class.mysql_xml.phtml
Role: Class source
Content type: text/plain
Description: Insert XML in MySQL and transform MySQL in XML using XMLFile class
Class: MySQL to XML - XML to MySQL
Insert XML in MySQL and export MySQL to XML
 

Contents

Class file image Download
<?php
//
// Por Ricardo Costa - ricardo.community@globo.com - 2002
// Classe conversão de query MySQL em XML
// Requer as classes recordSet e XMLFile 
//
//  mysql2xml
//    +---- recordSet    // Instancia de recordSet
//    +---- xml          // Instancia de XMLFile
//    +---- mysql2xml()  // Inicia as Instancias de recordset e XMLFile
//    +---- convertToXML( Seltença SQL, Nome do Arquivo )
//    +---- insertIntoMySQL( Nome do Arquivo, Nome da Tabela) {
//
//

require("class.recordset.phtml");
require(
"class.xml.phtml");



class 
mysql2xml {

   var 
$recordSet
   var 
$xml

   
# Inicializa criando os membros
   
function mysql2xml() {
      
$this->recordSet = new recordSet();
      
$this->xml = new XMLFile();
      
   }
   
# Inicializa criando os membros

   
   
   # Convert a query em XML
   
function convertToXML($sql$filename) {
      
$result $this->recordSet->select($sql);
      
      
$this->xml->create_root();
      
$this->xml->roottag->name "table";
   
      while (
$list_result $this->recordSet->setRow($result)) {

      
$this->xml->roottag->add_subtag("ROW", array());
      
$tag = &$this->xml->roottag->curtag;
            
         for (
$i 0$i <= $this->recordSet->fieldsCount($result)- 1$i++){
               
$tag->add_subtag($this->recordSet->getFieldName($result$i), array());
            
$tag->curtag->cdata $list_result[$i];
         }
      }
    
      
$xml_file fopen($filename"w" );
      
$this->xml->write_file_handle$xml_file );
   }
   
# Convert a query em XML

   
   
   # Inseri XML em tabela
   
function insertIntoMySQL($filename$tablename) {
      
$xml_file fopen($filename"r"); 
      
$this->xml->read_file_handle($xml_file);
          
      
$numRows $this->xml->roottag->num_subtags();
      
      for (
$i 0$i $numRows$i++) {
           
$arrFields null;
           
$arrValues null

           
$row $this->xml->roottag->tags[$i];
           
$numFields $row->num_subtags();

           for (
$ii 0$ii $numFields$ii++) {
               
$field $row->tags[$ii];
              
$arrFields[] = $field->name;
              
$arrValues[] = "\"".$field->cdata."\"";
           }

           
$fields join($arrFields", ");
           
$values join($arrValues", ");

           
$this->recordSet->exec("Insert Into $tablename ($fields) Values ($values)");
      }
   }
   
# Inseri XML em tabela


# Final da Classe
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products