databases
[ class tree: databases ] [ index: databases ] [ all elements ]

Source for file MySQLDatabaseTable.class.php

Documentation is available at MySQLDatabaseTable.class.php

  1. <?php
  2. /*
  3. if( !extension_loaded( 'mysql' ) )
  4.   dl( 'mysql.so' );
  5. */
  6. /**
  7.  * For including this file you have to define the constant "CLASSPATH".
  8.  * Because every include in the framework depends on the CLASSPATH definition.
  9.  * The CLASSPATH means the relative path to the folder that contains the
  10.  * framework GilliGan.
  11.  *
  12.  * @package    databases
  13.  * @subpackage mysql
  14.  */
  15. if!defined"CLASSPATH" ) )
  16. {
  17.   echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
  18.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
  19.   exit();
  20. }
  21.  
  22. /**
  23.  *
  24.  */
  25. include_once CLASSPATH."core/Arrays.class.php";
  26. /**
  27.  * Loading the supirior class on which this class depends.
  28.  */
  29. require_once CLASSPATH."databases/ABSTDatabaseTable.class.php";
  30. /**
  31.  *
  32.  */
  33. require_once CLASSPATH."databases/mysql/MySQL_constants.inc.php";
  34.  
  35. /**
  36.  * @package    databases
  37.  * @subpackage mysql
  38.  *
  39.  * @version    0.4.2
  40.  * @author     Daniel Plücken <daniel@debakel.net>
  41.  * @license    http://www.gnu.org/copyleft/lesser.html
  42.  *              GNU Lesser General Public License
  43.  * @copyright  Copyright (C) 2004 Daniel Plücken <daniel@debakel.net>
  44.  *
  45.  *  This library is free software; you can redistribute it and/or
  46.  *  modify it under the terms of the GNU Lesser General Public
  47.  *  License as published by the Free Software Foundation; either
  48.  *  version 2.1 of the License.
  49.  *
  50.  *  This library is distributed in the hope that it will be useful,
  51.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  52.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  53.  *  GNU Lesser General Public License for more details.
  54.  *
  55.  *  You should have received a copy of the GNU Lesser General
  56.  *  Public License along with this library; if not, write to the
  57.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  58.  *  Boston, MA 02111-1307 USA
  59.  */
  60. {
  61.   /**
  62.    * Constructor
  63.    *
  64.    * @access  public
  65.    * @version 1.0
  66.    * @since   0.1.0
  67.    *
  68.    * @param   string  $name 
  69.    * @param   object  $parent 
  70.    *
  71.    * @return  MySQLDatabaseTable 
  72.    */
  73.   function MySQLDatabaseTable$name$parent "" )
  74.   parent::__contructor$name"MySQL",  $parent )}
  75.  
  76.  
  77.  
  78.   /**
  79.    * @todo    This isn't programmed yet.
  80.    *
  81.    * @access  public
  82.    * @version 1.0
  83.    * @since   0.1.0
  84.    *
  85.    * @return void 
  86.    */
  87.   function researchFields()
  88.   {
  89.      if$this->probeConnection() )
  90.      {
  91.         //"SHOW COLUMNS FROM ".$this -> name;
  92.      }
  93.   }
  94.  
  95.  
  96.  
  97.   /**
  98.    * Iports data from a csv file. You have to create a CSVFiles-Object first.
  99.    *
  100.    * @access  public
  101.    * @version 1.0
  102.    * @since   0.1.0
  103.    *
  104.    * @param   CSVFiles $csv_file_obj 
  105.    * @param   array    $field_arr 
  106.    *
  107.    * @return  boolean 
  108.    */
  109.   function doCSVImport$csv_file_obj$field_arr "" )
  110.   {
  111.     $sqlOrder "LOAD DATA INFILE '".$csv_file_obj->path."/"
  112.                                     .$csv_file_obj->filename."' "
  113.                      ."INTO TABLE ".$this->name." "
  114.                      ."FIELDS TERMINATED BY '".$csv_file_obj->separator_char."' "
  115.                             ."ENCLOSED BY '".$csv_file_obj->enclosing_char."' "
  116.                             ."ESCAPED BY '".$csv_file_obj->escape_char."' "
  117.                      ."LINES TERMINATED BY '".$csv_file_obj->line_terminator_char."'"
  118.                      .(
  119.                         !empty$field_arr )
  120.                      && is_array$field_arr )
  121.                         ? "(`".implode"`, `"$field_arr )."`)"
  122.                         : ""
  123.                       );
  124.  
  125.     return $this->parent->query$sqlOrderfalse$this );
  126.   }
  127.  
  128.  
  129.  
  130.   /**
  131.    * Stores the Flags: (!)not_null <=> $this->field_can_be_null[FIELDINDEX],
  132.    * primary_key <=> $this->field_is_primary_member[FIELDINDEX], auto_increment
  133.    * <=> $this->field_has_auto_increment[FIELDINDEX]. This is necessary to get
  134.    * dump of the table data.
  135.    *
  136.    * @access  public
  137.    * @version 1.0
  138.    * @since   0.2.9
  139.    *
  140.    * @return  void 
  141.    */
  142.   function storeFieldFlags()
  143.   {
  144.      if(
  145.          !$this->field_flags_stored
  146.       && $this->probeConnection()
  147.        )
  148.      {
  149.        $sqlOrder "SELECT * "
  150.                    ."FROM `".$this->name."` "
  151.                    ."LIMIT 1";
  152.        $result   $this->parent->query$sqlOrderfalse$this );
  153.  
  154.        for $i 0$i mysql_num_fields$result )$i++ )
  155.        {
  156.            $tmp_str mysql_field_flags$result$i );
  157.  
  158.            $this->field_can_be_null[$i=
  159.                         strpos$tmp_str"not_null" === false;
  160.            $this->field_is_primary_member[$i=
  161.                         strpos$tmp_str"primary_key" !== false;
  162.            $this->field_has_auto_increment[$i=
  163.                         strpos$tmp_str"auto_increment" !== false;
  164.        }
  165.  
  166.        $this->field_flags_stored = true;
  167.      }
  168.   }
  169.  
  170.  
  171.  
  172.   /**
  173.    * Returns all field members of the primary key of this database
  174.    * table.
  175.    *
  176.    * @access  public
  177.    * @version 1.0
  178.    * @since   0.2.3
  179.    *
  180.    * @return  array|false
  181.    */
  182.   function &getPrimaryKey ()
  183.   {
  184.     ifis_array$this->primary_key ) )
  185.       return $this->primary_key;
  186.     if$this->probeConnection() )
  187.     {
  188.       $primary_key Array();
  189.  
  190.       $sqlOrder "SHOW KEYS FROM `".$this->name."`";
  191.       $result   $this->parent->query$sqlOrderfalse$this );
  192.  
  193.       while $res_arr @mysql_fetch_assoc$result ) )
  194.          if $res_arr["Key_name"== "PRIMARY" )
  195.             $primary_key[$res_arr["Column_name"];
  196.  
  197.       $this->last_query  = $sqlOrder;
  198.       $this->primary_key = $primary_key;
  199.  
  200.       return $this->primary_key;
  201.     }
  202.  
  203.     return false;
  204.   }
  205.  
  206.  
  207.  
  208.   /**
  209.    * Returns the fieldname of the auto increment field if there is one.
  210.    *
  211.    * @access  public
  212.    * @version 1.0
  213.    * @since   0.4.2
  214.    *
  215.    * @return  string 
  216.    */
  217.   function getAutoIncrementField()
  218.   {
  219.       if is_string$this->auto_increment_field ) )
  220.       {    return $this->auto_increment_field}
  221.  
  222.       if $this->probeConnection() )
  223.       {
  224.           $sqlOrder "SHOW COLUMNS FROM `".$this->name."`";
  225.           $result   $this->parent->query$sqlOrderfalse$this );
  226.  
  227.           while $res_arr @mysql_fetch_assoc$result ) )
  228.              if $res_arr["Extra"== "auto_increment" )
  229.                 $this->auto_increment_field = $res_arr["Field"];
  230.  
  231.           $this->last_query  = $sqlOrder;
  232.  
  233.           return $this->auto_increment_field;
  234.       }
  235.   }
  236.  
  237.  
  238.  
  239.   /**
  240.    * Returns an SQL-string to create this table. You can give a new name for
  241.    * creating the table.
  242.    *
  243.    * @access  public
  244.    * @version 1.4
  245.    * @since   0.1.0
  246.    *
  247.    * @param   string  $newTableName 
  248.    * @param   boolean $drop_order 
  249.    * @param   boolean $if_not_exists_order 
  250.    *
  251.    * @return  string 
  252.    */
  253.   function getCreateOrder(
  254.                             $newTableName        "",
  255.                             $drop_order          false,
  256.                             $if_not_exists_order false
  257.                          )
  258.   {
  259.     if$this->probeConnection() )
  260.     {
  261.       if $this->field_flags_stored )
  262.          $this->storeFieldFlags();
  263.  
  264.       $sqlOrder "SHOW CREATE TABLE `".$this->name."`";
  265.       $result   $this->parent->query$sqlOrderfalse$this );
  266.       $row      @mysql_fetch_row$result );
  267.  
  268.       $this->last_query = $sqlOrder;
  269.  
  270.       if $if_not_exists_order )
  271.          $begin substr$row[1]013 )."IF NOT EXISTS `";
  272.       else
  273.          $begin substr$row[1]014 );
  274.  
  275.       if empty$newTableName ) )
  276.         $row[1$begin.substr$row[1]14 );
  277.       else
  278.         $row[1$begin.$newTableName.substr(
  279.                              $row[1],
  280.                              14 strlen$this->name )
  281.                                              );
  282.  
  283.  
  284.  
  285.       if $drop_order )
  286.          $row[1"DROP TABLE IF EXISTS `".$this->name."`;\n".$row[1];
  287.  
  288.       return str_replace"\n""\r\n"$row[1).";\r\n";
  289.     }
  290.   }
  291.  
  292.  
  293.  
  294.   /**
  295.    * Returns an SQL-string to fill this table. You can give a new name for
  296.    * the table to insert in.
  297.    *
  298.    * @access  public
  299.    * @version 1.32
  300.    * @since   0.1.0
  301.    *
  302.    * @param   string  $newTableName 
  303.    * @param   boolean $full_inserts 
  304.    * @param   string  $where 
  305.    *
  306.    * @return  string 
  307.    */
  308.   function getDataOrder(
  309.                           $newTableName "",
  310.                           $full_inserts false,
  311.                           $where ""
  312.                        )
  313.   {
  314.     if !empty$where ) )
  315.        $sqlWhere " WHERE ".preg_replace"!^ *WHERE *!i"""$where );
  316.  
  317.     $this->storeFieldnames();
  318.     if $this->probeConnection() )
  319.     {
  320.         if empty$newTableName ) )
  321.            $newTableName $this->name;
  322.  
  323.         $sqlOrder "SELECT * "
  324.                    ."FROM `".$this->name."`".$sqlWhere;
  325.         $result   $this->parent->query$sqlOrderfalse$this );
  326.  
  327.         $out "";
  328.         while$row @mysql_fetch_row$result ) )
  329.         {
  330.             for $i 0$i count$row )$i++ )
  331.                 $row[$imysql_real_escape_string$row[$i);
  332.  
  333.             if !in_arraynull$row ) )
  334.                $out .= "INSERT INTO `".$newTableName."` "
  335.                                 .(
  336.                              $full_inserts
  337.                              ? "( `".implode"`, `"$this->fieldname )."` ) "
  338.                              : ""
  339.                                  )
  340.                            ."VALUES ( '".implode"', '"$row )."' );\r\n";
  341.             else
  342.             {
  343.                 $tmp "";
  344.                 for $i 0$i count$row )$i++ )
  345.                    if (
  346.                         $row[$i== null
  347.                      && $this->field_can_be_null[$i]
  348.                       )
  349.                       $tmp .= ", NULL";
  350.                    else
  351.                       $tmp .= ", '".$row[$i]."'";
  352.  
  353.                 $out .= "INSERT INTO `".$newTableName."` "
  354.                                 .(
  355.                              $full_inserts
  356.                              ? "( `".implode"`, `"$this->fieldname )."` ) "
  357.                              : ""
  358.                                  )
  359.                             ."VALUES ( ".substr$tmp)." );\r\n";
  360.             }
  361.         }
  362.         mysql_free_result$result );
  363.  
  364.         return $out;
  365.     }
  366.   }
  367.  
  368.  
  369.  
  370.   /**
  371.    * Copies this table.
  372.    *
  373.    * @access  public
  374.    * @version 1.1
  375.    * @since   0.1.0
  376.    *
  377.    * @param   string  $newTableName 
  378.    * @param   string  $targetDatabase 
  379.    *
  380.    * @return  boolean 
  381.    */
  382.   function copyTable$newTableName$targetDatabase "" )
  383.   {
  384.      $createSQL $this->getCreateOrder$newTableName );
  385.      if$this->probeConnection() )
  386.      {
  387.        ifempty$targetDatabase ) )
  388.          $targetDatabase $this->parent->name;
  389.  
  390.        $result @mysql_db_query$targetDatabase$createSQL );
  391.  
  392.        if$result )
  393.        {
  394.          $sql "INSERT INTO `".$targetDatabase."`.`".$newTableName."` "
  395.                     ."SELECT * "
  396.                       ."FROM `".$this->parent->name."`.`".$this->name."`";
  397.  
  398.          $res mysql_query$sql$this->parent->parent->resID );
  399.  
  400.          $this->last_query = $sql;
  401.        }
  402.      }
  403.  
  404.      return $res;
  405.   }
  406.  
  407.  
  408.  
  409.   /**
  410.    * Emptys this table.
  411.    *
  412.    * @access  public
  413.    * @version 1.0
  414.    * @since   0.1.0
  415.    *
  416.    * @return  boolean 
  417.    */
  418.   function emptyTable()
  419.   {
  420.      if$this -> probeConnection() )
  421.        $res $this->parent->query(
  422.                                     "TRUNCATE TABLE `".$this->name."`",
  423.                                     false$this
  424.                                   );
  425.  
  426.      return $res;
  427.   }
  428.  
  429.  
  430.  
  431.   /**
  432.    * Renames this table.
  433.    *
  434.    * @access  public
  435.    * @version 1.1
  436.    * @since   0.1.0
  437.    *
  438.    * @param   string  $newTableName 
  439.    *
  440.    * @return  boolean 
  441.    */
  442.   function renameTable$newTableName )
  443.   {
  444.      if$this -> probeConnection() )
  445.      {
  446.        $sqlOrder "ALTER TABLE `".$this->name."` RENAME `".$newTableName."`";
  447.        $res $this->parent->query$sqlOrderfalse$this );
  448.  
  449.        $this->last_query = $sqlOrder;
  450.      }
  451.  
  452.      return $res;
  453.   }
  454.  
  455.  
  456.  
  457.   /**
  458.    * Returns an SQL-DUMP.
  459.    *
  460.    * @access  public
  461.    * @version 1.2
  462.    * @since   0.1.0
  463.    *
  464.    * @param   string  $newTableName 
  465.    * @param   boolean $full_inserts 
  466.    * @param   boolean $drop_order 
  467.    * @param   boolean $if_not_exists_order 
  468.    *
  469.    * @return  string 
  470.    */
  471.   function getDump(
  472.               $newTableName        "",
  473.               $full_inserts        false,
  474.               $drop_order          false,
  475.               $if_not_exists_order false
  476.                   )
  477.   {
  478.     return $this->getCreateOrder(
  479.                          $newTableName,
  480.                          $drop_order,
  481.                          $if_not_exists_order
  482.                                 )."\r\n\r\n"
  483.           .$this->getDataOrder$newTableName$full_inserts )."\r\n\r\n";
  484.   }
  485.  
  486.  
  487.  
  488.   /**
  489.    * Returns an SQL-DUMP.
  490.    *
  491.    * @access  public
  492.    * @version 1.0
  493.    * @since   0.3.8
  494.    *
  495.    * @param   string  $newTableName 
  496.    * @param   boolean $full_inserts 
  497.    * @param   boolean $drop_order 
  498.    * @param   boolean $if_not_exists_order 
  499.    * @param   string  $where 
  500.    * @param   integer $flush_row_count 
  501.    *
  502.    * @return  string 
  503.    */
  504.   function echoBufferedDump(
  505.                                 $newTableName        "",
  506.                                 $full_inserts        false,
  507.                                 $drop_order          false,
  508.                                 $if_not_exists_order false,
  509.                                 $where               "",
  510.                                 $flush_row_count     1000
  511.                            )
  512.   {
  513.       echo $this->getCreateOrder(
  514.                                     $newTableName,
  515.                                     $drop_order,
  516.                                     $if_not_exists_order
  517.                                 )."\r\n\r\n";
  518.       ob_flush();
  519.       flush();
  520.  
  521.       $tmp_cnt $this->getCount$sqlWhere );
  522.  
  523.       if empty$where ) )
  524.          $where "1=1";
  525.  
  526.       for $i 0$i $tmp_cnt$i += $flush_row_count )
  527.       {
  528.           $tmp_where " LIMIT ".$i.", ".$flush_row_count;
  529.           echo $this->getDataOrder(
  530.                               $newTableName,
  531.                               $full_inserts,
  532.                               $where.$tmp_where
  533.                                   );
  534.           ob_flush();
  535.           flush();
  536.       }
  537.  
  538.       echo "\r\n\r\n";
  539.   }
  540.  
  541.  
  542.  
  543.   /**
  544.    * Returns the minimum value from a field.
  545.    *
  546.    * @access  public
  547.    * @version 1.0
  548.    * @since   0.2.7
  549.    *
  550.    * @param   string $fieldname 
  551.    * @param   string $where     The where-clause is optional.
  552.    *
  553.    * @return  integer 
  554.    */
  555.   function getMinOf$fieldname$where "" )
  556.   {
  557.     if$this->probeConnection() )
  558.     {
  559.       $res $this->parent->query(
  560.                                     "SELECT MIN( ".$fieldname." ) \r\n"
  561.                                    ."  FROM `".$this->name."`\r\n"
  562.                                      .(
  563.                                         !empty$where )
  564.                                         ? " WHERE ".$where
  565.                                         : ""
  566.                                       ),
  567.                                     false$this
  568.                                  );
  569.       $resArr @mysql_fetch_row$res );
  570.  
  571.       return $resArr[0];
  572.     }
  573.   }
  574.  
  575.  
  576.  
  577.   /**
  578.    * Returns the maximum value from a field.
  579.    *
  580.    * @access  public
  581.    * @version 1.1
  582.    * @since   0.1.0
  583.    *
  584.    * @param   string $fieldname 
  585.    * @param   string $where     The where-clause is optional.
  586.    *
  587.    * @return  integer 
  588.    */
  589.   function getMaxOf$fieldname$where "" )
  590.   {
  591.     if$this->probeConnection() )
  592.     {
  593.       $res $this->parent->query(
  594.                                     "SELECT MAX( ".$fieldname." ) \r\n"
  595.                                    ."  FROM `".$this->name."`\r\n"
  596.                                      .(
  597.                                         !empty$where )
  598.                                         ? " WHERE ".$where
  599.                                         : ""
  600.                                       ),
  601.                                     false$this
  602.                                  );
  603.       $resArr @mysql_fetch_row$res );
  604.  
  605.       return $resArr[0];
  606.     }
  607.   }
  608.  
  609.  
  610.  
  611.   /**
  612.    * Returns the sum value of a field.
  613.    *
  614.    * @access  public
  615.    * @version 1.0
  616.    * @since   0.3.3
  617.    *
  618.    * @param   string $fieldname 
  619.    * @param   string $where     The where-clause is optional.
  620.    *
  621.    * @return  integer 
  622.    */
  623.   function getSumOf$fieldname$where "" )
  624.   {
  625.     if$this->probeConnection() )
  626.     {
  627.       $res $this->parent->query(
  628.                                     "SELECT SUM( ".$fieldname." ) \r\n"
  629.                                    ."  FROM `".$this->name."`\r\n"
  630.                                      .(
  631.                                         !empty$where )
  632.                                         ? " WHERE ".$where
  633.                                         : ""
  634.                                       ),
  635.                                     false$this
  636.                                  );
  637.       $resArr @mysql_fetch_row$res );
  638.  
  639.       return $resArr[0];
  640.     }
  641.   }
  642.  
  643.  
  644.  
  645.   /**
  646.    * Returns the count of the fields in the where clause.
  647.    *
  648.    * @access  public
  649.    * @version 2.5
  650.    * @since   0.1.0
  651.    *
  652.    * @param   string $where 
  653.    *
  654.    * @return  integer 
  655.    */
  656.   function getCount$where "" )
  657.   {
  658.     if$this->probeConnection() )
  659.     {
  660.       $res $this->parent->query(
  661.                                     "SELECT COUNT( * ) \r\n"
  662.                                    ."  FROM `".$this->name."`\r\n"
  663.                                      .(
  664.                                         !empty$where )
  665.                                         ? " WHERE ".$where
  666.                                         : ""
  667.                                       ),
  668.                                     false$this
  669.                                  );
  670.       $resArr @mysql_fetch_row$res );
  671.  
  672.       return $resArr[0];
  673.     }
  674.   }
  675.  
  676.  
  677.  
  678.   /**
  679.    * Returns the datasets as an two dimensional array if the query could be
  680.    * execute. The first dimension carries the datasets. The second dimension
  681.    * carries the fields's values of the result list.
  682.    *
  683.    * Usage:
  684.    *          getDatasetsWithFields( $fieldnamesArr, $where );
  685.    * Or:
  686.    *          getDatasetsWithFields( $where, $array_kind );
  687.    * Or:
  688.    *          getDatasetsWithFields( $where );
  689.    *
  690.    * @access  public
  691.    * @version 1.7
  692.    * @since   0.1.5
  693.    *
  694.    * @param   array  $field_arr  The fields that should be in the result list.
  695.    * @param   string $where      The where clause of the query.
  696.    * @param   string $only_one 
  697.    * @param   string $array_kind The kind how the tuples should be output.
  698.    *                              MYSQL_OUTPUT_ASSOC - to get an associative
  699.    *                              array, with the fieldnames as indices.
  700.    *                              MYSQL_OUTPUT_NUM - to get an array, with
  701.    *                              numbers as indices in order of the
  702.    *                              $fieldnamesArr or of the underlying table.
  703.    *                              MYSQL_OUTPUT_DEFAULT - to get a mix of both
  704.    *                              output kinds.
  705.    * @return  array 
  706.    */
  707.   function getDatasetsWithFields(
  708.                                    $field_arr array(),
  709.                                    $where "1=1",
  710.                                    $only_one false,
  711.                                    $array_kind MYSQL_OUTPUT_DEFAULT
  712.                                 )
  713.   {
  714.      $param func_get_args();
  715.  
  716.      if (
  717.           is_array$field_arr )
  718.        && !empty$where )
  719.         )
  720.         $sqlWhere " WHERE ".preg_replace"!^ *WHERE *!i"""$where );
  721.      else
  722.      if (
  723.           is_string$field_arr )
  724.        && !empty$field_arr )
  725.         )
  726.      {
  727.         $sqlWhere " WHERE ".preg_replace"!^ *WHERE *!i"""$field_arr );
  728.  
  729.         if (
  730.              $where === MYSQL_OUTPUT_ASSOC
  731.          ||  $where === MYSQL_OUTPUT_NUM
  732.          ||  $where === MYSQL_OUTPUT_DEFAULT
  733.            )
  734.            $array_kind $where;
  735.      }
  736.  
  737.      if !is_array$field_arr ) )
  738.         $sqlOrder "SELECT * "
  739.                      ."FROM `".$this->name."`".$sqlWhere;
  740.      else
  741.      {
  742.        $sqlResultFields implode", "$field_arr );
  743.  
  744.        $sqlOrder "SELECT ".$sqlResultFields
  745.                    ." FROM `".$this->name."`".$sqlWhere;
  746.      }
  747.  
  748.      if $this->probeConnection() )
  749.         $result $this->parent->query$sqlOrderfalse$this );
  750.  
  751.  
  752.      if $only_one )
  753.      {
  754.         if $array_kind == MYSQL_OUTPUT_ASSOC // MYSQL_OUTPUT_ASSOC
  755.            return @mysql_fetch_assoc$result );
  756.         elseif $array_kind == MYSQL_OUTPUT_NUM // MYSQL_OUTPUT_NUM
  757.            return @mysql_fetch_row$result );
  758.         else // MYSQL_OUTPUT_DEFAULT
  759.            return @mysql_fetch_array$result );
  760.      }
  761.      else
  762.      {
  763.         $i 0;
  764.         $dataset_arr array();
  765.         if $array_kind == MYSQL_OUTPUT_ASSOC // MYSQL_OUTPUT_ASSOC
  766.         while $result_arr @mysql_fetch_assoc$result ) )
  767.         {
  768.            $dataset_arr[$iarray();
  769.            $dataset_arr[$i++$result_arr;
  770.         }
  771.         elseif $array_kind == MYSQL_OUTPUT_NUM // MYSQL_OUTPUT_NUM
  772.         while $result_arr @mysql_fetch_row$result ) )
  773.         {
  774.            $dataset_arr[$iarray();
  775.            $dataset_arr[$i++$result_arr;
  776.         }
  777.         else // MYSQL_OUTPUT_DEFAULT
  778.         while $result_arr @mysql_fetch_array$result ) )
  779.         {
  780.            $dataset_arr[$iarray();
  781.            $dataset_arr[$i++$result_arr;
  782.         }
  783.  
  784.         return $dataset_arr;
  785.      }
  786.   }
  787.  
  788.  
  789.   /**
  790.    * This method is an alias for the method "getDatasetsWithFields".
  791.    * Returns the datasets as an two dimensional array if the query could be
  792.    * execute. The first dimension carries the datasets. The second dimension
  793.    * carries the fields's values of the result list.
  794.    *
  795.    * Usage:
  796.    *          getDatasets( $fieldnamesArr, $where, $array_kind );
  797.    * Or:
  798.    *          getDatasets( $where );
  799.    *
  800.    * @access  public
  801.    * @version 1.4
  802.    * @since   0.1.5
  803.    *
  804.    * @param   string  $fields_or_where   The fields to extract from relation.
  805.    * @param   string  $where_or_only_one The where clause of the query.
  806.    * @param   string  $array_kind        The kind how the tuples should be
  807.    *                                      output.
  808.    *                                      MYSQL_OUTPUT_ASSOC - to get an
  809.    *                                      associative array, with the fieldnames
  810.    *                                      as indices.
  811.    *                                      MYSQL_OUTPUT_NUM - to get an array,
  812.    *                                      with numbers as indices in order of the
  813.    *                                      $fieldnamesArr or of the underlying
  814.    *                                      table.
  815.    *                                      MYSQL_OUTPUT_DEFAULT - to get a mix of
  816.    *                                      both output kinds.
  817.    * @param   boolean $only_one          Whether only one Dataset should be
  818.    *                                      output.
  819.    * @or
  820.    * @param   string  $fields_or_where   The where clause of the query.
  821.    * @param   boolean $where_or_only_one Whether only one Dataset should be
  822.    *                                      output.
  823.    * @param   string  $array_kind        The kind how the tuples should be
  824.    *                                      output.
  825.    *                                      MYSQL_OUTPUT_ASSOC - to get an
  826.    *                                      associative array, with the fieldnames
  827.    *                                      as indices.
  828.    *                                      MYSQL_OUTPUT_NUM - to get an array,
  829.    *                                      with numbers as indices in order of the
  830.    *                                      $fieldnamesArr or of the underlying
  831.    *                                      table.
  832.    *                                      MYSQL_OUTPUT_DEFAULT - to get a mix of
  833.    *                                      both output kinds.
  834.    * @return  array 
  835.    */
  836.   function getDatasets(
  837.                         $fields_or_where "1=1",
  838.                         $where_or_only_one false,
  839.                         $array_kind MYSQL_OUTPUT_DEFAULT,
  840.                         $only_one false
  841.                       )
  842.   {
  843.      if (
  844.           is_string$fields_or_where )
  845.        && is_bool$where_or_only_one )
  846.         )
  847.      {
  848.         $field_arr $this->getFieldnames();
  849.  
  850.         return $this->getDatasetsWithFields(
  851.                                      $field_arr,
  852.                                      $fields_or_where,
  853.                                      $where_or_only_one,
  854.                                      $array_kind
  855.                                            );
  856.      }
  857.      /*
  858.      else
  859.      {
  860.      */
  861.          if !is_array$fields_or_where ) )
  862.             $field_arr explode","$fields_or_where );
  863.          else
  864.             $field_arr =$fields_or_where;
  865.  
  866.          return $this->getDatasetsWithFields(
  867.                                               $fields_or_where,
  868.                                               $where_or_only_one,
  869.                                               $only_one,
  870.                                               $array_kind
  871.                                             );
  872.      // }
  873.   }
  874.  
  875.  
  876.  
  877.   /**
  878.    * Returns the datasets as array with the values of the primary key as index.
  879.    *
  880.    * @access  public
  881.    * @version 1.21
  882.    * @since   0.1.8
  883.    *
  884.    * @param   array  $primary_key  The fields that should be in the result list.
  885.    * @param   array  $value_fields The fields with the values for the content.
  886.    * @param   string $where        The where clause of the query.
  887.    *
  888.    * @return  array 
  889.    */
  890.                                           $primary_key,
  891.                                           $value_fields,
  892.                                           $where null
  893.                                         )
  894.   {
  895.      if !empty$where ) )
  896.      {  $sqlWhere " WHERE ".$where}
  897.  
  898.      $str_value "";
  899.      if is_string$value_fields ) )
  900.      {  $str_value $value_fields}
  901.      else
  902.      if is_array$value_fields ) )
  903.      {  $str_value implode", "$value_fields )}
  904.  
  905.      $sqlOrder "SELECT `".$primary_key."`, "
  906.                            .$str_value." "
  907.                   ."FROM `".$this->name."`".$sqlWhere;
  908.  
  909.      if $this->probeConnection() )
  910.      {  $result $this->parent->query$sqlOrderfalse$this )}
  911.  
  912.      // strip aliases from primary field list
  913.      $primary_key preg_replace(
  914.                                     "!^.+? +AS +([-_a-z0-9]+)$!is",
  915.                                     "$1"$primary_key
  916.                                  );
  917.  
  918.      while $resultArr @mysql_fetch_array$result ) )
  919.      {
  920.         if is_array$value_fields ) )
  921.         {  $datasets$resultArr[$primary_key] ] $resultArr}
  922.         else
  923.         if is_string$value_fields ) )
  924.         {
  925.            // strip aliases from field list
  926.            $value_fields preg_replace(
  927.                                           "!^.+? +AS +([-_a-z0-9]+)$!is",
  928.                                           "$1"$value_fields
  929.                                        );
  930.  
  931.            $datasets$resultArr[$primary_key] ] $resultArr[$value_fields];
  932.         }
  933.      }
  934.  
  935.      return $datasets;
  936.   }
  937.  
  938.  
  939.  
  940.   /**
  941.    * Returns the datasets as array with the values of the primary key as index.
  942.    *
  943.    * @access  public
  944.    * @version 1.11
  945.    * @since   0.1.8
  946.    *
  947.    * @param   array  $primary_key  The fields that should be in the result list.
  948.    * @param   array  $value_fields The fields with the values for the content.
  949.    * @param   string $where        The where clause of the query.
  950.    *
  951.    * @return  array 
  952.    */
  953.                                              $primary_key,
  954.                                              $value_fields,
  955.                                              $where null
  956.                                            )
  957.   {
  958.      if !empty$where ) )
  959.      {  $sqlWhere "WHERE ".$where." "}
  960.  
  961.      $str_value "";
  962.      if is_string$value_fields ) )
  963.      {  $str_value $value_fields}
  964.      else
  965.      if is_array$value_fields ) )
  966.      {  $str_value implode", "$value_fields )}
  967.  
  968.      $sqlOrder "SELECT `".$primary_key."`, "
  969.                            .$str_value." "
  970.                   ."FROM `".$this->name."` "
  971.                   .$sqlWhere
  972.               ."ORDER BY `".$primary_key."` ASC";
  973.  
  974.      if $this->probeConnection() )
  975.      {  $result $this->parent->query$sqlOrderfalse$this )}
  976.  
  977.      // strip aliases from primary field list
  978.      $primary_key preg_replace(
  979.                                     "!^.+? +AS +([-_a-z0-9]+)$!is",
  980.                                     "$1"$primary_key
  981.                                 );
  982.  
  983.      while $resultArr @mysql_fetch_array$result ) )
  984.      {
  985.         if is_array$value_fields ) )
  986.         {  $datasets$resultArr[$primary_key] ][$resultArr}
  987.         else
  988.         if is_string$value_fields ) )
  989.         {
  990.            // strip aliases from field list
  991.            $value_fields preg_replace(
  992.                                           "!^.+? +AS +([-_a-z0-9]+)$!is",
  993.                                           "$1"$value_fields
  994.                                        );
  995.  
  996.            $datasets$resultArr[$primary_key] ][$resultArr[$value_fields];
  997.         }
  998.      }
  999.  
  1000.      return $datasets;
  1001.   }
  1002.  
  1003.  
  1004.  
  1005.   /**
  1006.    * Returns a single dataset as an array if the query could be execute.
  1007.    *
  1008.    * @access  public
  1009.    * @version 1.3
  1010.    * @since   0.1.2
  1011.    *
  1012.    * @param   string  $fields_or_where 
  1013.    * @param   string  $where 
  1014.    * @param   string  $array_kind The kind how the tuples should be output.
  1015.    *                               MYSQL_OUTPUT_ASSOC - to get an associative
  1016.    *                               array, with the fieldnames as indices.
  1017.    *                               MYSQL_OUTPUT_NUM - to get an array, with
  1018.    *                               numbers as indices in order of the
  1019.    *                               $fieldnamesArr or of the underlying table.
  1020.    *                               MYSQL_OUTPUT_DEFAULT - to get a mix of both
  1021.    *                               output kinds.
  1022.    * @return  array 
  1023.    */
  1024.   function getSingleDataset(
  1025.                              $fields_or_where,
  1026.                              $where "",
  1027.                              $array_kind MYSQL_OUTPUT_DEFAULT
  1028.                            )
  1029.   {
  1030.      ifis_array$fields_or_where ) )
  1031.        $tmp implode", "$fields_or_where );
  1032.      else
  1033.      {
  1034.        $where =$fields_or_where;
  1035.        $tmp "*";
  1036.      }
  1037.  
  1038.      $sqlWhere " WHERE ".$where;
  1039.  
  1040.      $sqlOrder "SELECT ".$tmp." \r\n"
  1041.                 ."  FROM `".$this->name."`\r\n".$sqlWhere;
  1042.  
  1043.      if $this->probeConnection() )
  1044.         $result $this->parent->query$sqlOrderfalse$this );
  1045.  
  1046.      if $array_kind == MYSQL_OUTPUT_ASSOC // MYSQL_OUTPUT_ASSOC
  1047.         return @mysql_fetch_assoc$result );
  1048.      else
  1049.      if $array_kind == MYSQL_OUTPUT_NUM // MYSQL_OUTPUT_NUM
  1050.         return @mysql_fetch_row$result );
  1051.      else // MYSQL_OUTPUT_DEFAULT
  1052.         return @mysql_fetch_array$result );
  1053.   }
  1054.  
  1055.  
  1056.  
  1057.   /**
  1058.    * Returns a single value of a data field.
  1059.    *
  1060.    * @access  public
  1061.    * @version 1.0
  1062.    * @since   0.2.8
  1063.    *
  1064.    * @param   string  $fieldname 
  1065.    * @param   string  $where 
  1066.    *
  1067.    * @return  mixed 
  1068.    */
  1069.   function getSingleDataFieldValue$fieldname$where )
  1070.   {
  1071.      $sqlWhere " WHERE ".$where;
  1072.  
  1073.      $sqlOrder "SELECT ".$fieldname." \r\n"
  1074.                 ."  FROM `".$this->name."`\r\n".$sqlWhere;
  1075.  
  1076.      if$this->probeConnection() )
  1077.        $result $this->parent->query$sqlOrderfalse$this );
  1078.  
  1079.      $tmp_row @mysql_fetch_row$result );
  1080.  
  1081.      return $tmp_row[0];
  1082.   }
  1083.  
  1084.  
  1085.  
  1086.   /**
  1087.    * Returns a array of values of a data field.
  1088.    *
  1089.    * @access  public
  1090.    * @version 1.0
  1091.    * @since   0.3.1
  1092.    *
  1093.    * @param   string  $fieldname 
  1094.    * @param   string  $where 
  1095.    *
  1096.    * @return  mixed 
  1097.    */
  1098.   function getArrayOfDataField$fieldname$where )
  1099.   {
  1100.      $sqlWhere " WHERE ".$where;
  1101.  
  1102.      $sqlOrder "SELECT ".$fieldname." \r\n"
  1103.                 ."  FROM `".$this->name."`\r\n".$sqlWhere;
  1104.  
  1105.      if$this->probeConnection() )
  1106.        $result $this->parent->query$sqlOrderfalse$this );
  1107.  
  1108.      $tmp_arr array();
  1109.      while $tmp_row @mysql_fetch_row$result ) )
  1110.            $tmp_arr[$tmp_row[0];
  1111.  
  1112.      return $tmp_arr;
  1113.   }
  1114.  
  1115.  
  1116.  
  1117.   /**
  1118.    * Puts a single dataset into request-variables. The names of the request-vars
  1119.    * accord to the fieldnames of the Databasetable. You can fill variables of
  1120.    * the types: $_REQUEST, $_GET and $_POST. You only have to list them in an
  1121.    * array passed as third parameter in this function (see the description for
  1122.    * third parameter).
  1123.    *
  1124.    * @access  public
  1125.    * @version 1.0
  1126.    * @since   0.4.1
  1127.    *
  1128.    * @param   string|array$where_or_field_arr This has to be the where-clause
  1129.    *                                            of the query to the underlying
  1130.    *                                            database table. If you only want
  1131.    *                                            to fetch and put a few fields of
  1132.    *                                            the table, you schould pass here
  1133.    *                                            an array of fieldnames and pass
  1134.    *                                            the where-clause to the with
  1135.    *                                            parameter.
  1136.    * @param   string       $where              This has to be the where-clause
  1137.    *                                            of the query to the underlying
  1138.    *                                            database table, if the first
  1139.    *                                            parameter should carry the fields
  1140.    *                                            that are only to fetch.
  1141.    * @param   array        $request_type_arr   Valid Values are:
  1142.    *                                            array( "GET", "POST", "REQUEST" )
  1143.    *                                             You can leave out the array
  1144.    *                                             values you don't need that the
  1145.    *                                             field values put in according
  1146.    *                                             request-variables.
  1147.    *
  1148.    * @return  void 
  1149.    */
  1150.                       $where_or_field_arr,
  1151.                       $where "",
  1152.                       $request_type_arr array"GET""POST""REQUEST" )
  1153.                                             )
  1154.   {
  1155.     if is_array$where_or_field_arr ) )
  1156.     {  $field_arr =$where_or_field_arr}
  1157.     else
  1158.     {
  1159.        $where =$where_or_field_arr;
  1160.        $field_arr $this->getRealFieldnames();
  1161.     }
  1162.  
  1163.     $res_arr $this->getSingleDataset$where );
  1164.  
  1165.     # Datatransfer
  1166.     if $res_arr && $field_arr )
  1167.     {
  1168.         if in_array"GET"$request_type_arr ) )
  1169.         foreach $field_arr as $fieldname )
  1170.         {  $_GET$fieldname $res_arr$fieldname ]}
  1171.  
  1172.         if in_array"POST"$request_type_arr ) )
  1173.         foreach $field_arr as $fieldname )
  1174.         {  $_POST$fieldname $res_arr$fieldname ]}
  1175.  
  1176.         if in_array"REQUEST"$request_type_arr ) )
  1177.         foreach $field_arr as $fieldname )
  1178.         {  $_REQUEST$fieldname $res_arr$fieldname ]}
  1179.     }
  1180.   }
  1181.  
  1182.  
  1183.  
  1184.   /**
  1185.    * Puts a single dataset into "post"-variables. The names of the "Post"-vars
  1186.    * accord to the fieldnames of the Databasetable.
  1187.    *
  1188.    * @access  public
  1189.    * @version 1.21
  1190.    * @since   0.1.5
  1191.    *
  1192.    * @see     MySQLDatabaseTable::putSingleDatasetIntoRequestVars()
  1193.    *
  1194.    * @param   string|array$where_or_field_arr 
  1195.    * @param   string       $where 
  1196.    *
  1197.    * @return  void 
  1198.    */
  1199.   function putSingleDatasetIntoPostVars$where_or_field_arr$where "" )
  1200.   $this->putSingleDatasetIntoRequestVars$where_or_field_arr$wherearray"POST" ) )}
  1201.  
  1202.  
  1203.  
  1204.   /**
  1205.    * Puts a single dataset into "get"-variables. The names of the "get"-vars
  1206.    * accord to the fieldnames of the Databasetable.
  1207.    *
  1208.    * @access  public
  1209.    * @version 1.21
  1210.    * @since   0.1.5
  1211.    *
  1212.    * @see     MySQLDatabaseTable::putSingleDatasetIntoRequestVars()
  1213.    *
  1214.    * @param   string|array$where_or_field_arr 
  1215.    * @param   string       $where 
  1216.    *
  1217.    * @return  void 
  1218.    */
  1219.   function putSingleDatasetIntoGetVars$where_or_field_arr$where "" )
  1220.   $this->putSingleDatasetIntoRequestVars$where_or_field_arr$wherearray"GET" ) )}
  1221.  
  1222.  
  1223.  
  1224.  
  1225.   /**
  1226.    * Deletes the specified dataset.
  1227.    *
  1228.    * @access  public
  1229.    * @version 1.0
  1230.    * @since   0.2.1
  1231.    *
  1232.    * @param   string $where 
  1233.    *
  1234.    * @return  boolean 
  1235.    */
  1236.   function delete$where )
  1237.   {
  1238.     ifempty$where ) )
  1239.       die(
  1240.            "It is not allowed to leave the where-clause blank.\r\n<br />"
  1241.           ."Use the method \"emptyTable\" to remove all datasets.\r\n<br />"
  1242.           ."If you want to keep the actual auto-increment-value, then try\r\n"
  1243.           ."to call this function like delete( \"1=1\" );\r\n<br />"
  1244.          );
  1245.     else
  1246.     {
  1247.        $sqlOrder "DELETE FROM `".$this->name."`\r\n"
  1248.                   ."      WHERE ".$where;
  1249.  
  1250.        if$this->probeConnection() )
  1251.          $result $this->parent->query$sqlOrderfalse$this );
  1252.  
  1253.        return $result;
  1254.     }
  1255.   }
  1256.  
  1257.  
  1258.   /**
  1259.    * Inserts the specified dataset. Note that this function will create a global
  1260.    * variable $GLOBALS["insert_id"] which contains the result of
  1261.    * mysql_insert_id();
  1262.    *
  1263.    * @access  public
  1264.    * @version 1.66
  1265.    * @since   0.1.1
  1266.    *
  1267.    * @param   array   $fieldArr  The array that carries the fieldnames.
  1268.    * @param   array   $valueArr  The array that carries the values.
  1269.    *
  1270.    * @return  boolean 
  1271.    */
  1272.   function insert$fieldArr$valueArr )
  1273.   {
  1274.        $sqlSetFields  "";
  1275.        $fieldname_arr $this->getRealFieldnames();
  1276.  
  1277.        $tmp_fields_key_arr array_keys$fieldArr );
  1278.        $tmp_value_key_arr array_keys$valueArr );
  1279.        for $i 0$i count$fieldArr )$i++ )
  1280.         if in_array$fieldArr$tmp_fields_key_arr[$i] ]$fieldname_arr ) )
  1281.            $sqlSetFields .= "`".$fieldArr$tmp_fields_key_arr[$i] ]."` = "
  1282.                            ."'".mysql_real_escape_string(
  1283.                                          $valueArr$tmp_value_key_arr[$i] ]
  1284.                                                         )."', ";
  1285.  
  1286.        $sqlSetFields substr$sqlSetFields0strlen$sqlSetFields );
  1287.  
  1288.        $sqlOrder "INSERT INTO `".$this->name."` "
  1289.                           ."SET ".$sqlSetFields;
  1290.  
  1291.        if $this->probeConnection() )
  1292.        {
  1293.           $result $this->parent->query$sqlOrderfalse$this );
  1294.           $this->insert_id = $GLOBALS["insert_id"@mysql_insert_id();
  1295.        }
  1296.  
  1297.        return $result;
  1298.   }
  1299.  
  1300.  
  1301.  
  1302.   /**
  1303.    * Updates the specified dataset.
  1304.    *
  1305.    * @access  public
  1306.    * @version 1.46
  1307.    * @since   0.1.1
  1308.    *
  1309.    * @param   array   $fieldArr The array that carries the fieldnames.
  1310.    * @param   array   $valueArr The array that carries the values.
  1311.    * @param   string  $where    The wheredefinition of the query.
  1312.    *
  1313.    * @return  boolean 
  1314.    */
  1315.   function update$fieldArr$valueArr$where "1=1" )
  1316.   {
  1317.        $sqlSetFields "";
  1318.        $fieldname_arr $this->getRealFieldnames();
  1319.  
  1320.        $tmp_fields_key_arr array_keys$fieldArr );
  1321.        $tmp_value_key_arr array_keys$valueArr );
  1322.        for $i 0$i count$fieldArr )$i++ )
  1323.         if in_array$fieldArr$tmp_fields_key_arr[$i] ]$fieldname_arr ) )
  1324.            $sqlSetFields .= "`".$fieldArr$tmp_fields_key_arr[$i] ]."` = "
  1325.                            ."'".mysql_real_escape_string(
  1326.                                          $valueArr$tmp_value_key_arr[$i] ]
  1327.                                                         )."', ";
  1328.  
  1329.        $sqlSetFields substr$sqlSetFields0strlen$sqlSetFields );
  1330.  
  1331.        $sqlOrder "UPDATE `".$this->name."` "
  1332.                      ."SET ".$sqlSetFields." "
  1333.                    ."WHERE ".$where;
  1334.  
  1335.        if$this->probeConnection() )
  1336.          $result $this->parent->query$sqlOrderfalse$this );
  1337.  
  1338.        return $result;
  1339.   }
  1340.  
  1341.  
  1342.  
  1343.   /**
  1344.    * Replaces the specified dataset.
  1345.    *
  1346.    * @access  public
  1347.    * @version 1.16
  1348.    * @since   0.2.0
  1349.    *
  1350.    * @param   array   $fieldArr The array that carries the fieldnames.
  1351.    * @param   array   $valueArr The array that carries the values.
  1352.    *
  1353.    * @return  boolean 
  1354.    */
  1355.   function replace$fieldArr$valueArr )
  1356.   {
  1357.        $sqlSetFields "";
  1358.        $fieldname_arr $this->getRealFieldnames();
  1359.  
  1360.        $tmp_fields_key_arr array_keys$fieldArr );
  1361.        $tmp_value_key_arr array_keys$valueArr );
  1362.        for $i 0$i count$fieldArr )$i++ )
  1363.         if in_array$fieldArr$tmp_fields_key_arr[$i] ]$fieldname_arr ) )
  1364.            $sqlSetFields .= "`".$fieldArr$tmp_fields_key_arr[$i] ]."` = "
  1365.                            ."'".mysql_real_escape_string(
  1366.                                          $valueArr$tmp_value_key_arr[$i] ]
  1367.                                                         )."', ";
  1368.  
  1369.        $sqlSetFields substr$sqlSetFields0strlen$sqlSetFields );
  1370.  
  1371.        $sqlOrder "REPLACE INTO `".$this->name."` "
  1372.                            ."SET ".$sqlSetFields;
  1373.  
  1374.        if $this->probeConnection() )
  1375.        {
  1376.           $result $this->parent->query$sqlOrderfalse$this );
  1377.           $this->insert_id = $GLOBALS["insert_id"@mysql_insert_id();
  1378.        }
  1379.  
  1380.        return $result;
  1381.   }
  1382.  
  1383.  
  1384.  
  1385.   /**
  1386.    * Swaps values of a specified field in two tupel.
  1387.    *
  1388.    * @access  public
  1389.    * @version 1.0
  1390.    * @since   0.3.2
  1391.    *
  1392.    * @param   string  $fieldname 
  1393.    * @param   string  $where_a 
  1394.    * @param   string  $where_b 
  1395.    *
  1396.    * @return  boolean 
  1397.    */
  1398.   function swapFieldValuesOf$fieldname$where_a$where_b )
  1399.   {
  1400.      $help_a $this->getSingleDataFieldValue$fieldname$where_a );
  1401.      $help_b $this->getSingleDataFieldValue$fieldname$where_b );
  1402.      // because of unique conflicts
  1403.      $this->updatearray$fieldname )array'' )$where_a );
  1404.      $this->updatearray$fieldname )array$help_a )$where_b );
  1405.      $this->updatearray$fieldname )array$help_b )$where_a );
  1406.   }
  1407.  
  1408.  
  1409.  
  1410.   /**
  1411.    * Stores the names of fields in this object.
  1412.    *
  1413.    * @access  public
  1414.    * @version 1.1
  1415.    * @since   0.1.0
  1416.    *
  1417.    * @return  boolean 
  1418.    */
  1419.   function storeFieldnames()
  1420.   {
  1421.     if!$this->field_names_stored )
  1422.     {
  1423.       if(
  1424.           !empty$this->parent->name )
  1425.        && !empty$this->name )
  1426.         )
  1427.       {
  1428.          if$this->probeConnection() )
  1429.            $result $this->parent->query(
  1430.                                 "SHOW COLUMNS FROM `".$this->name."`",
  1431.                                 false$this
  1432.                                          );
  1433.          if$result )
  1434.          {
  1435.            while$arr @mysql_fetch_assoc$result ) )
  1436.              $this->fieldname[$arr["Field"];
  1437.  
  1438.            $this->field_names_stored   = true;
  1439.            $this->overruled_fieldnames = false;
  1440.            return $result;
  1441.          }
  1442.  
  1443.          return $result;
  1444.       }
  1445.     }
  1446.   }
  1447.  
  1448.  
  1449.  
  1450.   /**
  1451.    * Returns the table's fieldnames independence of overruled fieldnames. If you
  1452.    * want you can get the fieldnames enclosed in backticks.
  1453.    *
  1454.    * @access  public
  1455.    * @version 1.1
  1456.    * @since   0.1.3
  1457.    *
  1458.    * @param   boolean $backticks 
  1459.    *
  1460.    * @return  array 
  1461.    */
  1462.   function getRealFieldnames$backticks false )
  1463.   {
  1464.     $fieldname_arr array();
  1465.     if(
  1466.         !empty$this->parent->name )
  1467.      && !empty$this->name )
  1468.       )
  1469.     {
  1470.        if$this->probeConnection() )
  1471.          $result $this->parent->query(
  1472.                               "SHOW COLUMNS FROM `".$this->name."`",
  1473.                               false$this
  1474.                                        );
  1475.        if$result )
  1476.          while$arr @mysql_fetch_assoc$result ) )
  1477.            $fieldname_arr[$arr["Field"];
  1478.     }
  1479.  
  1480.     if!$backticks )
  1481.       return $fieldname_arr;
  1482.     else
  1483.     {
  1484.       $tmp_str "`".implode"`[[SEPARATOR]]`"$fieldname_arr )."`";
  1485.       return explode"[[SEPARATOR]]"$fieldname_arr );
  1486.     }
  1487.   }
  1488.  
  1489.  
  1490.  
  1491.   /**
  1492.    * Returns the table's fieldnames. If you want you can get the fieldnames
  1493.    * enclosed in backticks.
  1494.    *
  1495.    * @access  public
  1496.    * @version 1.3
  1497.    * @since   0.1.1
  1498.    *
  1499.    * @param   boolean $backticks 
  1500.    *
  1501.    * @return  array 
  1502.    */
  1503.   function getFieldnames$backticks false )
  1504.   {
  1505.     ifArrays::is_empty$this->fieldname ) )
  1506.       $this->storeFieldnames();
  1507.  
  1508.     if!Arrays::is_empty$this->fieldname ) )
  1509.       if!$backticks )
  1510.         return $this->fieldname;
  1511.       else
  1512.       {
  1513.         $tmp_str "`".implode"`[[SEPARATOR]]`"$this->fieldname )."`";
  1514.         return explode"[[SEPARATOR]]"$tmp_str );
  1515.       }
  1516.  
  1517.     return array();
  1518.   }
  1519.  
  1520.  
  1521.  
  1522.   /**
  1523.    * Overrules the table's fieldnames. The given array should contain the comma
  1524.    * separated list of the query between the keywords SELECT and FROM.
  1525.    * Each element of the array should represent one element of the list.
  1526.    *
  1527.    * @access  public
  1528.    * @version 1.0
  1529.    * @since   0.2.3
  1530.    *
  1531.    * @param   array  $array 
  1532.    *
  1533.    * @return  void 
  1534.    */
  1535.   function overruleFieldnames$array )
  1536.   {
  1537.     $this->fieldname = $array;
  1538.     $this->field_names_stored   = true;
  1539.     $this->overruled_fieldnames = true;
  1540.   }
  1541.  
  1542.  
  1543.  
  1544.   /**
  1545.    * Unsets the overrules of fieldnames.
  1546.    *
  1547.    * @access  public
  1548.    * @version 1.0
  1549.    * @since   0.2.7
  1550.    *
  1551.    * @return  void 
  1552.    */
  1553.   function unsetOverruledFieldnames()
  1554.   {
  1555.     unset$this->fieldname );
  1556.     $this->fieldname = null;
  1557.  
  1558.     $this->field_names_stored   = false;
  1559.     $this->overruled_fieldnames = false;
  1560.   }
  1561.  
  1562.  
  1563.  
  1564.   /**
  1565.    * Probes whether there is a connection to the databasehost, if not it will
  1566.    * attempt to connect to the host.
  1567.    *
  1568.    * @access  public
  1569.    * @version 1.2
  1570.    * @since   0.1.0
  1571.    *
  1572.    * @return boolean 
  1573.    */
  1574.   function probeConnection()
  1575.   {
  1576.      iffunction_exists"debug_backtrace" ) )
  1577.        $debugArr debug_backtrace();
  1578.  
  1579.      if(
  1580.          (
  1581.             !function_exists"is_a" )
  1582.          && get_class$this->parent != "mysqldatabase"
  1583.          || function_exists"is_a" )
  1584.          && !is_a$this->parent"MySQLDatabase" )
  1585.          )
  1586.       && (
  1587.            defined"DEBUG" )
  1588.         || SCRIPTDEBUGGING
  1589.          )
  1590.        )
  1591.      {
  1592.        echo "There is no valid parent-object for the object of the "
  1593.            ."databasetable named \"".$this -> name."\".<br />\r\n"
  1594.            ."Please add this table-object to a database-object before you "
  1595.            ."make a call such as on <b>line&nbsp;"
  1596.            .$debugArr[count($debugArr)-1]["line"]."</b> in <b>file&nbsp;\""
  1597.            .$debugArr[count($debugArr)-1]["file"]."\"</b>."
  1598.            ."<br /><br />\r\n";
  1599.        echo "<b>BACKTRACE DEBUG:</b><br />\r\n";
  1600.        echo "<pre>\r\n";
  1601.        print_r$debugArr );
  1602.        echo "</pre>\r\n";
  1603.        exit();
  1604.      }
  1605.      else
  1606.      if(
  1607.          (
  1608.             !function_exists"is_a" )
  1609.          && get_class$this->parent->parent != "mysqldatabasehost"
  1610.          || function_exists"is_a" )
  1611.          && !is_a$this->parent->parent"MySQLDatabaseHost" )
  1612.          )
  1613.       && (
  1614.            defined"DEBUG" )
  1615.         || SCRIPTDEBUGGING
  1616.          )
  1617.        )
  1618.      {
  1619.        echo "The parent object of this databasetable-object has no parent."
  1620.            ."<br />\r\n"
  1621.            ."Please add the object of the database named "
  1622.            ."\"".$this->parent->name."\" and which contains the object of "
  1623.            ."the table \"".$this->name."\" to a databasehost-object before "
  1624.            ."you make a call such as on <b>line&nbsp;"
  1625.            .$debugArr[count($debugArr)-1]["line"]."</b> in <b>file&nbsp;\""
  1626.            .$debugArr[count($debugArr)-1]["file"]."\"</b>."
  1627.            ."<br />\r\n";
  1628.        echo "<b>BACKTRACE DEBUG</b><br />\r\n";
  1629.        echo "<pre>\r\n";
  1630.        print_r$debugArr );
  1631.        echo "</pre>\r\n";
  1632.        exit();
  1633.      }
  1634.      else
  1635.      if!$this->parent->parent->is_connected )
  1636.        $this->parent->parent->connect();
  1637.  
  1638.      if$this->parent->parent->is_connected )
  1639.        return true;
  1640.      else
  1641.        return false;
  1642.   }
  1643. // End of class MySQLDatabaseTable
  1644. ?>

Documentation generated on Thu, 05 Jun 2008 19:14:20 +0200 by phpDocumentor 1.4.1