"Fossies" - the Fresh Open Source Software Archive

Member "mythreads/lib/phplib/db_usql.inc" (29 Mar 2001, 2381 Bytes) of package /linux/privat/mythreads-links_1.2.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "db_usql.inc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.0_vs_1.2.1.

    1 <?php
    2 /*
    3  * PHP Base Library
    4  *
    5  * general utilities for db_sql
    6  *
    7  * (c) 1999-2000 Carmelo Guarneri
    8  *
    9  * $Id: db_usql.inc,v 1.1 2001-03-29 21:51:52 ldrolez 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 ?>