home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / database / usql.class.inc < prev   
Text File  |  2004-03-08  |  2KB  |  77 lines

  1. <?php
  2. /*
  3.  * PHP Base Library
  4.  *
  5.  * general utilities for db_sql
  6.  *
  7.  * (c) 1999-2000 Carmelo Guarneri
  8.  *
  9.  * $Id: usql.class.inc,v 1.1.1.1 2003/07/03 15:04:02 mschering Exp $
  10.  *
  11.  */
  12.  
  13.  
  14. class DB_USql extends DB_Sql {
  15.  
  16. //--------------------------------------------------------------
  17. //  this function can be used to export all the columns of
  18. //  a record into global variables.
  19. //  It should be used after a call to next_record().
  20. //--------------------------------------------------------------
  21.   function import_record_vars() {
  22.     while (list($key, $val) = each($this->Record))
  23.     if (ereg("[A-Za-z][A-Za-z0-9_]*", $key)) {
  24.       $field_name = strtoupper($key);
  25.       global $$field_name;
  26.       $$field_name=$val;
  27.     };
  28.   }
  29.  
  30. //--------------------------------------------------------------
  31. //  this function can be used to export all the records of
  32. //  a table on the output in the form of a call to the db_sql
  33. //  query function with an insert statement.
  34. //--------------------------------------------------------------
  35.   function dump_table($tablename, $filter="") {
  36.     $this->query(sprintf("select * from %s", $tablename));
  37.     while ($this->next_record()) {
  38.       $this->dump_record($tablename, $filter);
  39.     };
  40.   }
  41.  
  42. //--------------------------------------------------------------
  43. //  this function can be used to export all the records of
  44. //  a query on the output in the form of a call to the db_sql
  45. //  query function with an insert statement.
  46. //--------------------------------------------------------------
  47.   function dump_query($tablename, $filter="") {
  48.     //$this->query(sprintf("select * from %s", $tablename));
  49.     while ($this->next_record()) {
  50.       $this->dump_record($tablename, $filter);
  51.     };
  52.   }
  53.  
  54.   function dump_record($tablename, $filter="") {
  55.     $fields="";
  56.     $values="";
  57.     while (list($key, $val) = each($this->Record))
  58.     if (ereg("[A-Za-z][A-Za-z0-9_]*", $key)) {
  59.       $field_name = strtoupper($key);
  60.       if (!empty($val))
  61.       if (strstr( $filter, $field_name )=="") {
  62.         $fields.="$field_name ,";
  63.         $val=ereg_replace("'","''",$val);
  64.         $val=ereg_replace("\"","\\\"",$val);
  65.         //addslashes($val);
  66.         $values.="'$val' ,";
  67.       };
  68.     }
  69.     $fields=substr($fields, 0, strlen($fields)-1);
  70.     $values=substr($values, 0, strlen($values)-1);
  71.     $insert=sprintf("insert into %s(%s) values(%s)", $tablename, $fields, $values);
  72.     echo "\$db->query(\"$insert\");\n";
  73.   }
  74.   };
  75.  
  76. ?>
  77.