|
|
|
|
|
|
| |
This is the supporting class that retrieves the tables views and creates the backup of the views .
This is an extension of the DBXML Class .
U will need this class to work with DBXML properly.
Any bugs or class design issuez in this class please mail "TAB_STRUCT : Bug Mail " in the subject line.
Any bugs or class design issuez in DBXML please mail "DBXML : Bug Mail " in the subject line.
if anybody have any job oppz for PHP or want support please feel free to contact me.It wuld b of great help.
NOTE: Be careful about the " '.A single change will cause problem in viewing the XML file.
The next class is coming for generation DTDs customised ones!!!
Thank you for the support
| <?php
class TAB_STRUCT
{
function xml_tbl_create($tbl)
{
$creat="";
$sql = "SHOW CREATE TABLE ".$tbl."";
$res = mysql_query($sql) or die(mysql_error());
$creat="<create_table value=\"".$tbl."\">";
while ($row = mysql_fetch_assoc($res))
{
$creat=$creat.$row["Create Table"]."</create_table>";
}
return $creat;
}
function tbl_struct_xml($db,$tbl,$fnme)
{
$tt="";
mysql_select_db($db) or die("Could not select database");
$fnme=$fnme.$tbl."_STRUCT.xml";
$sql = "DESC ".$db.".".$tbl."";
$res = mysql_query($sql) or die(mysql_error());
$ft=fopen($fnme,"w");
$tt="<?xml version=\"1.0\"?".">"."<xml><".$db."><".$tbl."_struct>".TAB_STRUCT::xml_tbl_create($tbl).TAB_STRUCT::gen_insert($db,$tbl);
while ($row = mysql_fetch_assoc($res))
{
$tt=$tt."<field_start><name>".$row["Field"]."</name><type>".$row["Type"]."</type><is_null>".$row["Null"]."</is_null><is_key>".$row["Key"]."</is_key><default_value>".$row["Default"]."</default_value></field_start>";
}
$tt=$tt."</".$tbl."_struct></".$db."></xml>";
$bw=fwrite($ft,$tt);
$d=fclose($ft);
Return $d;
}
function show_db_status($db)
{
$stat="";
$fnme="C:\\".$db."_status.xml";
$sql="SHOW TABLE STATUS";
mysql_select_db($db) or die("Could not select database");
$t_stat= mysql_query($sql) or die(mysql_error());
$ft=fopen($fnme,"w");
$stat="<?xml version=\"1.0\"?".">"."<xml><".$db.">";
while ($row = mysql_fetch_assoc($t_stat))
{
$stat=$stat."<table><name>".$row"Name"]."</name><records>".$row["Rows"]."</records><row_format>".$row["Row_format"]."</row_format><type>".$row["Type"]."</type></table>";
}
$stat=$stat."</".$db."></xml>";
$bw=fwrite($ft,$stat);
$d=fclose($ft);
Return $d;
}
function gen_insert($db,$tbl)
{
$fd = mysql_list_fields($db,$tbl);
$col = mysql_num_fields($fd);
$ins="<insert_prototype value=\"".$tbl."\">INSERT INTO ".$tbl." ( ";
$ins=$ins.mysql_field_name($fd,0);
for ($i = 1; $i < $col; $i++)
{
$ins=$ins." , ".mysql_field_name($fd, $i);
}
$ins=$ins.") VALUES(";
for ($i = 0; $i < $col; $i++)
{
$k=mysql_field_type($fd,$i);
switch($k)
{
case "int" : $ins=$ins." , ";
break;
case "real" : $ins=$ins."0.00, ";
break;
case "float" : $ins=$ins." 0.0, ";
break;
case "varchar(100)" : $ins=$ins."\'vchr100\',";
break;
case "varchar(50)" : $ins=$ins."\'vchr50\' ,";
break;
case "char" : $ins=$ins.",";
break;
case "blob" : $ins=$ins."'blob',";
break;
case "string" : $ins=$ins."'',";
break;
default : $ins=$ins.",";
break;
}
}
$ins=$ins.")</insert_prototype>";
return $ins;
}
}
?> | | |
|
| DBXML- A Class to backup databases in XML Format using web interface Categories : PHP, PHP Classes, Databases, MySQL, XML | | | Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP, PHP Classes, Databases, MySQL, Navigation | | | Password reminder Categories : PHP, PHP Classes, Databases, MySQL, Mail | | | MySQL Class to ease Database connectivity Categories : MySQL, PHP Classes, Databases, PHP | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | | | PostGreSQL and MySQL 2 in 1 db Manager Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL | | | Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Simple usersOnline class - keep track of how many users are online on your site Categories : PHP, PHP Classes, Databases, MySQL | | | Online Automatic Class Generator for MySQL Tables Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP. Categories : PHP Classes, Databases, PHP, MySQL, InnoDB | | | Ajax PHP Tree (Left and Right) with MySQL Categories : PHP, Databases, MySQL, AJAX, PHP Classes | | | YellowPages Content Grabber (PHP5 +) Categories : PHP, PHP Classes, Regexps, Databases, MySQL | |
|
|
|