PHP Classes

File: example_mysql.php

Recommend this page to a friend!
  Classes of Alessandro Vernassa (speleoalex)   XML DB   example_mysql.php   Download  
File: example_mysql.php
Role: Example script
Content type: text/plain
Description: example mysql
Class: XML DB
Manage XML and MySQL databases using SQL
Author: By
Last change:
Date: 6 years ago
Size: 1,848 bytes
 

Contents

Class file image Download
<?php
require_once ("include/xmldb.php");
require_once (
"include/xmldb_query.php");

$xml ='<?xml version="1.0" encoding="UTF-8"?>
<?php exit(0);?>
<tables>
    <field>
        <name>id</name>
        <primarykey>1</primarykey>
        <defaultvalue></defaultvalue>
        <type>string</type>
        <extra>autoincrement</extra>
    </field>
    <field>
        <name>stringfield</name>
        <primarykey>0</primarykey>
        <defaultvalue>the name</defaultvalue>
        <type>string</type>
    </field>
    <field>
        <name>textfield</name>
        <type>text</type>
    </field>
    <field>
        <name>intfield</name>
        <type>int</type>
    </field>
    <driver>mysql</driver>
</tables>'
;

$dbname="dbtest";
$dbtable="mysqltable";
$dbpath=".";

if (!
file_exists($dbname))
{
   
mkdir($dbname);
}
if (!
file_exists("$dbpath/$dbname/$dbtable.php"))
{
   
file_put_contents("$dbpath/$dbname/$dbtable.php",$xml);
}

global
$xmldb_mysqlconnection;
$xmldb_mysqlconnection=new mysqli("localhost","root","");
echo
"<pre>contents \"$dbname/$dbtable.php\"\n";
echo(
htmlspecialchars(file_get_contents("$dbpath/$dbname/$dbtable.php")));
echo
"</pre>";


$Table=new XMLTable("$dbname","$dbtable",$dbpath);
$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 $dbtable 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>";
}