Php > Databases sample source codes
TAB_STRUCT Class Is supporting Class for the DBXML Class
TAB_STRUCT Class Is supporting Class for the DBXML Class /* 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 */ class TAB_STRUCT { function xml_tbl_create($tbl) { $creat=""; $sql = "SHOW CREATE TABLE ".$tbl.""; $res = mysql_query($sql) or die(mysql_error()); $creat="
"; while ($row = mysql_fetch_assoc($res)) { $creat=$creat.$row["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=""."
<".$db."><".$tbl."_struct>".TAB_STRUCT::xml_tbl_create($tbl).TAB_STRUCT::gen_insert($db,$tbl); while ($row = mysql_fetch_assoc($res)) { $tt=$tt."
".$row["Field"]."
".$row["Type"]."
".$row["Null"]."
".$row["Key"]."
".$row["Default"]."
"; } $tt=$tt."".$tbl."_struct>".$db.">
"; $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=""."
<".$db.">"; while ($row = mysql_fetch_assoc($t_stat)) { $stat=$stat."
".$row"Name"]."
".$row["Rows"]."
".$row["Row_format"]."
".$row["Type"]."
"; } $stat=$stat."".$db.">
"; $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 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.")
"; return $ins; } } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage