Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Nico Puhlmann  >  XML2DB  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: This file explains how to use and call the class
Class: XML2DB
Generate SQL queries to import data from XML files
Author: By
Last change:
Date: 2005-05-02 07:07
Size: 1,407 bytes
 

Contents

Class file image Download
<?
// +----------------------------------------------------------------------+
// | xml2db / Example                                                     |
// | Creating SQL Queries from a xml file                                 |
// | Requirements: PHP5 with SimpleXML Support                            |
// | This file explains how to use and call the class                     |
// +----------------------------------------------------------------------+
// | Author: Nico Puhlmann <nico@puhlmann.com>                            |
// +----------------------------------------------------------------------+
// $Id: example.php,v 1.0 2oo5/o4/29 18:11:23 npuhlmann Exp $

include( dirname(__FILE__) . "/class.xml2db.php");

// Call the class with the root element of the xml data
$xml2db = new xml2db("product");

// Set (path to) XML file
$xml2db->setXMLFile("test.xml");

// The table name for the insert queries
$xml2db->setTable("cellphones");

// configuration array
$xml2db->setData(array
(
    
//         xml node    type        db field        attr name
    
array(    "",            "attr",        "id",            "id"    ),
    array(    
"brand",    "node",        "manufacturer"            ),
    array(    
"brand",    "attr",        "type",            "type"    ),
    array(    
"model",    "node",        "name"    ),
    array(    
"price",    "node",        "price"    ),
));

// Just a test printout - you can perfom the queries here
echo "<pre>";
print_r($xml2db->getQueries());
echo 
"</pre>";
?>