PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alessandro Vernassa (speleoalex)  >  XML DB  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: sample XMLTable and XMLDatabase classes
Class: XML DB
Manage XML and MySQL databases using SQL
Author: By
Last change:
Date: 5 years ago
Size: 1,245 bytes
 

Contents

Class file image Download
<?php
/**
 * Created on 19-mag-2006
 *
 */
require_once ("xmldb.php");

$fields[0]['name']="id";
$fields[0]['primarykey']=1;
$fields[0]['defaultvalue']=null;
$fields[0]['type']="string";
$fields[0]['extra']="autoincrement";

$fields[1]['name']="stringfield";
$fields[1]['primarykey']=0;
$fields[1]['defaultvalue']="the name";
$fields[1]['type']="string";

$fields[2]['name']="textfield";
$fields[2]['type']="text";

//---create xml database---
$err = createxmldatabase("dbtest",".");
echo
$err."<br />";
//---create xml table---
$err .= createxmltable("dbtest","test",$fields,".");
echo
$err;

$Table= new XMLTable("dbtest","test",".");

$records = $Table->GetRecords();
if (!
$records || count ($records) < 5)
{
   
//---insert new record
   
$vals['stringfield']="this is string value";
   
$vals['textfield']="this is text value";
   
$recordinsert = $Table->InsertRecord($vals);
   
$records = $Table->GetRecords();
}

//print records
echo "<pre>\$Table->GetRecords();\n";
print_r($records);
echo
"</pre>";

if (
is_array($records))
{
   
$query= "SELECT * FROM test ORDER BY id DESC LIMIT 1,5";
   
$DB= new XMLDatabase("dbtest",".");
   
$records = $DB->query($query);
    echo
"<pre>";
    echo
"\$DB->query(\"$query\") :\n";
   
print_r($records);
    echo
"</pre>";
   
}

?>