diogenes.database.table.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00027 class DiogenesDatabaseTable {
00029   var $dbh;
00031   var $table;
00033   var $vars = array();
00034 
00040   function DiogenesDatabaseTable(&$dbh,$table)
00041   {
00042     $this->dbh =& $dbh;
00043     $this->table = $table;
00044 
00045     $res = $this->dbh->query("show columns from $table");
00046     while (list($name,$ftype,,$key,$value,$extra) = mysql_fetch_row($res))
00047     {
00048       if (!preg_match("/^([a-z]+)(\(([^\)]*)\))?( [a-z]+)?$/",$ftype,$matches))
00049         die("could not parse $ftype");
00050 
00051       $dtype = $matches[1];
00052       switch($dtype) {
00053       case "set": case "enum":
00054         $type = "set";
00055         break;
00056       case "timestamp":
00057       case "datetime":
00058         $type = "timestamp";
00059         break;
00060       default:
00061         $type="text";
00062       }
00063       $this->vars[$name] = array("table" => $this->table, "field" => $name,
00064         "type" => $type, "value" => $value, "desc" => $name, "sum" => false,
00065         "key" => $key, "extra" => $extra, "edit" => true, "show" => true);
00066     }
00067     mysql_free_result($res);
00068   }
00069 
00070 }
00071 
00072 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1