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

Source for file MySQLView.class.php

Documentation is available at MySQLView.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    databases
  9.  * @subpackage mysql
  10.  */
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
  15.   exit();
  16. }
  17.  
  18. /**
  19.  * Loading the superior class on which this class depends.
  20.  */
  21. require_onceCLASSPATH."databases/ABSTView.class.php" );
  22. /**
  23.  * Loading functions to handle arrays.
  24.  */
  25. include_onceCLASSPATH."core/Arrays.class.php" );
  26. /**
  27.  *
  28.  */
  29. require_once CLASSPATH."databases/mysql/MySQL_constants.inc.php";
  30.  
  31. /**
  32.  * @package    databases
  33.  * @subpackage mysql
  34.  *
  35.  * @version    0.2.12
  36.  * @author     Daniel Plücken <daniel@debakel.net>
  37.  * @license    http://www.gnu.org/copyleft/lesser.html
  38.  *              GNU Lesser General Public License
  39.  * @copyright  Copyright (C) 2005 Daniel Plücken <daniel@debakel.net>
  40.  *
  41.  *  This library is free software; you can redistribute it and/or
  42.  *  modify it under the terms of the GNU Lesser General Public
  43.  *  License as published by the Free Software Foundation; either
  44.  *  version 2.1 of the License.
  45.  *
  46.  *  This library is distributed in the hope that it will be useful,
  47.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  48.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49.  *  GNU Lesser General Public License for more details.
  50.  *
  51.  *  You should have received a copy of the GNU Lesser General
  52.  *  Public License along with this library; if not, write to the
  53.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  54.  *  Boston, MA 02111-1307 USA
  55.  */
  56. class MySQLView extends ABSTView
  57. {
  58.   /**
  59.    * Stores the condition on every query with this view. It is helpful to define
  60.    * inner joins in the where clause.
  61.    *
  62.    * @var    object $dbt_right 
  63.    * @access public
  64.    */
  65.   var $fixed_where = "";
  66.  
  67.  
  68.   /**
  69.    * Constructor
  70.    *
  71.    * @version 1.0
  72.    * @since   0.1.0
  73.    * @author  Daniel Plücken <daniel@debakel.net>
  74.    * @access  public
  75.    * @param   string  $name* 
  76.    */
  77.   function MySQLView$name "" )
  78.   parent::__constructor$name )}
  79.  
  80.  
  81.  
  82.   /**
  83.    * Sets the condition of first priority.
  84.    *
  85.    * @version 1.0
  86.    * @since   0.1.8
  87.    * @author  Daniel Plücken <daniel@debakel.net>
  88.    * @access  public
  89.    * @param   string $string 
  90.    * @return  string 
  91.    */
  92.   function setFixedWhere$string )
  93.   $this->fixed_where = "( ".$string." ) AND ( "}
  94.  
  95.  
  96.  
  97.   /**
  98.    * Returns the correct where clause from given where concate the fixed where.
  99.    *
  100.    * @version 1.0
  101.    * @since   0.1.8
  102.    * @author  Daniel Plücken <daniel@debakel.net>
  103.    * @access  private
  104.    * @param   string $string 
  105.    * @return  string 
  106.    */
  107.   function getCorrectWhere$string )
  108.   {
  109.     if empty$this->fixed_where ) )
  110.        return $string;
  111.     else
  112.     {
  113.        $out $this->fixed_where;
  114.  
  115.        if (
  116.              preg_match(
  117.                   "!^(?:GROUP BY|ORDER BY|LIMIT|PROCEDURE|INTO OUTFILE)!i",
  118.                   $string
  119.                        )
  120.           )
  121.           $string "1=1 ".$string;
  122.  
  123.        $str_copy strtoupper$string );
  124.        $int_pos array();
  125.        $int_pos[strpos$str_copy"GROUP BY" );
  126.        $int_pos[strpos$str_copy"ORDER BY" );
  127.        $int_pos[strpos$str_copy"LIMIT" );
  128.        $int_pos[strpos$str_copy"PROCEDURE" );
  129.        $int_pos[strpos$str_copy"INTO OUTFILE" );
  130.  
  131.        // remove failed matching entries
  132.        for $i count$int_pos 1$i >= 0$i-- )
  133.            if $int_pos[$i=== false )
  134.               array_splice$int_pos$i);
  135.  
  136.        // no position found
  137.        if count$int_pos <= )
  138.           $out .= $string." )";
  139.        else
  140.        {
  141.           $closing_pos min$int_pos );
  142.           $out .= substr_replace$string" ) "$closing_pos);
  143.        }
  144.  
  145.        return $out;
  146.     }
  147.   }
  148.  
  149.  
  150.  
  151.   /**
  152.    * Returns the order to join the database tables in the query.
  153.    *
  154.    * @version 1.0
  155.    * @since   0.1.8
  156.    * @author  Daniel Plücken <daniel@debakel.net>
  157.    * @access  public
  158.    * @param   array   $field_arr In-out-parameter.
  159.    * @return  string 
  160.    */
  161.   function getJoinOrder&$field_arr )
  162.   {
  163.      // Fields of the left database table
  164.      $tmpFArr1  array();
  165.      // Fields of the right database table
  166.      $tmpFArr2  array();
  167.      // Return variable
  168.      $tmp_joins "";
  169.  
  170.  
  171.      for $i 0$i count$this->join )$i++ )
  172.      {
  173.        $tmpFArr1 $this->join[$i]->dbt_left->getFieldnames(
  174.                          !$this->join[$i]->dbt_left->overruled_fieldnames
  175.                                                            );
  176.        for$k 0$k count$tmpFArr1 )$k++ )
  177.        {
  178.           $tmp_str preg_replace(
  179.                                     "!^(.+?) +AS +[-_a-z0-9]+$!is",
  180.                                     "$1"$tmpFArr1[$k]
  181.                                  );
  182.           // Setting up the field list
  183.           Arrays::uniqueInsert(
  184.                  $field_arr,
  185.                  preg_replace(
  186.                                "!(`[-_a-z0-9]+`)!is",
  187.                                $this->join[$i]->alias_left.".$1",
  188.                                $tmp_str
  189.                              )." "
  190.                 ."AS ".$this->join[$i]->alias_left."_"
  191.                 # extracting aliases
  192.                 .preg_replace"!^.*?([-_a-z0-9]+)`?$!is""$1"$tmpFArr1[$k)
  193.                               );
  194.        }
  195.  
  196.  
  197.        $tmpFArr2 $this->join[$i]->dbt_right->getFieldnames(
  198.                          !$this->join[$i]->dbt_right->overruled_fieldnames
  199.                                                             );
  200.        for$k 0$k count$tmpFArr2 )$k++ )
  201.        {
  202.           $tmp_str preg_replace(
  203.                                     "!^(.+?) +AS +[-_a-z0-9]+$!is",
  204.                                     "$1"$tmpFArr2[$k]
  205.                                  );
  206.           // Setting up the field list
  207.           Arrays::uniqueInsert(
  208.                  $field_arr,
  209.                  preg_replace(
  210.                                "!(`[-_a-z0-9]+`)!is",
  211.                                $this->join[$i]->alias_right.".$1",
  212.                                $tmp_str
  213.                              )." "
  214.                 ."AS ".$this->join[$i]->alias_right."_"
  215.                 # extracting aliases
  216.                 .preg_replace"!^.*?([-_a-z0-9]+)`?$!is""$1"$tmpFArr2[$k)
  217.                               );
  218.        }
  219.  
  220.        $tmp_joins .= $this->join[$i]->type
  221.                     ." JOIN `".$this->join[$i]->dbt_right->name."` "
  222.                        ."AS ".$this->join[$i]->alias_right." "
  223.                        .(
  224.                           strpos$this->type"NATURAL" === false
  225.                           ? "ON "
  226.                           : ""
  227.                         );
  228.        $k 0;
  229.        do
  230.        {
  231.           ifempty$this->join[$i]->relational_operator[$k) )
  232.             $this->join[$i]->relational_operator[$k"=";
  233.  
  234.           $tmp_joins .= (
  235.                           $k == 0
  236.                           ? ""
  237.                           : (
  238.                 strtoupper$this->join[$i]->logical_operator[$k-1== "AND"
  239.                 ? "      AND "
  240.                 : "       OR "
  241.                             )
  242.                         ).$this->join[$i]->alias_left."."
  243.                          .$this->join[$i]->left_field[$k]." "
  244.                          .$this->join[$i]->relational_operator[$k]." "
  245.                          .(
  246.                     strtoupper$this->join[$i]->right_field[$k!= "NULL"
  247.                  && strtoupper$this->join[$i]->right_field[$k!= "NOT NULL"
  248.                             ? $this->join[$i]->alias_right."."
  249.                             : ""
  250.                           )
  251.                          .$this->join[$i]->right_field[$k]." \r\n";
  252.  
  253.           $k++;
  254.        }
  255.        while$k <= count$this->join[$i]->logical_operator ) );
  256.      }
  257.  
  258.      return $tmp_joins;
  259.   }
  260.  
  261.  
  262.  
  263.   /**
  264.    * Returns the datasets as an array if the query could be execute.
  265.    * Notice that the fieldnames will be output in the special form that the
  266.    * given alias of a table and the responsed fieldname are separated by an
  267.    * underscore, for example "alias_fieldname".
  268.    *
  269.    * @version 1.7
  270.    * @since   0.1.1
  271.    * @author  Daniel Plücken <daniel@debakel.net>
  272.    * @access  public
  273.    * @param   string  $fields_or_where   The fields to extract from relation.
  274.    * @param   string  $where_or_only_one The where clause of the query.
  275.    * @param   string  $array_kind        The kind how the tuples should be
  276.    *                                      output.
  277.    *                                      MYSQL_OUTPUT_ASSOC - to get an
  278.    *                                      associative array, with the fieldnames
  279.    *                                      as indices.
  280.    *                                      MYSQL_OUTPUT_NUM - to get an array,
  281.    *                                      with numbers as indices in order of the
  282.    *                                      $fieldnamesArr or of the underlying
  283.    *                                      table.
  284.    *                                      MYSQL_OUTPUT_DEFAULT - to get a mix of
  285.    *                                      both output kinds.
  286.    * @param   boolean $only_one          Whether only one Dataset should be
  287.    *                                      output.
  288.    * @or
  289.    * @param   string  $fields_or_where   The where clause of the query.
  290.    * @param   boolean $where_or_only_one Whether only one Dataset should be
  291.    *                                      output.
  292.    * @param   string  $array_kind        The kind how the tuples should be
  293.    *                                      output.
  294.    *                                      MYSQL_OUTPUT_ASSOC - to get an
  295.    *                                      associative array, with the fieldnames
  296.    *                                      as indices.
  297.    *                                      MYSQL_OUTPUT_NUM - to get an array,
  298.    *                                      with numbers as indices in order of the
  299.    *                                      $fieldnamesArr or of the underlying
  300.    *                                      table.
  301.    *                                      MYSQL_OUTPUT_DEFAULT - to get a mix of
  302.    *                                      both output kinds.
  303.    * @return  boolean|array
  304.    */
  305.   function getDatasets(
  306.                         $fields_or_where "1=1",
  307.                         $where_or_only_one false,
  308.                         $array_kind MYSQL_OUTPUT_DEFAULT,
  309.                         $only_one false
  310.                       )
  311.   {
  312.      if (
  313.           is_string$fields_or_where )
  314.        && is_bool$where_or_only_one )
  315.         )
  316.      {
  317.         $field_arr array();
  318.         $str_join $this->getJoinOrder$field_arr );
  319.         $field_arr array_merge$field_arr$this->custom_field_arr );
  320.  
  321.         return $this->getDatasetsWithFields(
  322.                                      $field_arr,
  323.                                      $fields_or_where,
  324.                                      $where_or_only_one,
  325.                                      $array_kind
  326.                                            );
  327.      }
  328.      /*
  329.      else
  330.      {
  331.      */
  332.         if !is_array$fields_or_where ) )
  333.            $field_arr explode","$fields_or_where );
  334.         else
  335.            $field_arr =$fields_or_where;
  336.  
  337.         return $this->getDatasetsWithFields(
  338.                                      $field_arr,
  339.                                      $where_or_only_one,
  340.                                      $only_one,
  341.                                      $array_kind
  342.                                            );
  343.      // }
  344.   }
  345.  
  346.  
  347.  
  348.   /**
  349.    * Returns the datasets as array with the values of the primary key as index.
  350.    *
  351.    * @version 1.0
  352.    * @since   0.2.0
  353.    * @author  Daniel Plücken <daniel@debakel.net>
  354.    * @access  public
  355.    * @param   array  $primary_key  The fields that should be in the result list.
  356.    * @param   array  $value_fields The fields with the values for the content.
  357.    * @param   string $where        The where clause of the query.
  358.    * @return  array 
  359.    */
  360.                                           $primary_key,
  361.                                           $value_fields,
  362.                                           $where ""
  363.                                         )
  364.   {
  365.      $field_arr array();
  366.      $str_join $this->getJoinOrder$field_arr );
  367.  
  368.      if !empty$where ) )
  369.         $sqlWhere " WHERE ".$where;
  370.  
  371.      $str_value "";
  372.      if is_string$value_fields ) )
  373.         $str_value $value_fields;
  374.      else
  375.      if is_array$value_fields ) )
  376.         foreach $value_fields as $str_value_field )
  377.         {
  378.           if !empty$str_value ) )
  379.              $str_value .= ", ";
  380.  
  381.           $str_value .= $str_value_field;
  382.         }
  383.  
  384.      $sqlOrder "SELECT ".$primary_key.", "
  385.                           .$str_value." "
  386.                   ."FROM `".$this->join[0]->dbt_left->name."` "
  387.                      ."AS ".$this->join[0]->alias_left." "
  388.                            .$str_join
  389.                            .$sqlWhere;
  390.  
  391.      $result $this->join[0]->dbt_left->parent->query$sqlOrderfalse$this );
  392.  
  393.      $primary_key preg_replace(
  394.                                     "!^.+? +AS +([-_a-z0-9]+)$!is",
  395.                                     "$1"$primary_key
  396.                                  );
  397.  
  398.      while $resultArr @mysql_fetch_array$result ) )
  399.         if is_string$value_fields ) )
  400.         {
  401.            $value_fields preg_replace(
  402.                                           "!^.+? +AS +([-_a-z0-9]+)$!is",
  403.                                           "$1"$value_fields
  404.                                        );
  405.  
  406.            $datasets$resultArr[$primary_key] ] $resultArr[$value_fields];
  407.         }
  408.         else
  409.         if is_array$value_fields ) )
  410.            $datasets$resultArr[$primary_key] ] $resultArr;
  411.  
  412.      return $datasets;
  413.   }
  414.  
  415.  
  416.  
  417.   /**
  418.    * Returns the datasets as array with the values of the primary key as index.
  419.    *
  420.    * @version 1.0
  421.    * @since   0.2.0
  422.    * @author  Daniel Plücken <daniel@debakel.net>
  423.    * @access  public
  424.    * @param   array  $primary_key  The fields that should be in the result list.
  425.    * @param   array  $value_fields The fields with the values for the content.
  426.    * @param   string $where        The where clause of the query.
  427.    * @return  array 
  428.    */
  429.                                              $primary_key,
  430.                                              $value_fields,
  431.                                              $where ""
  432.                                            )
  433.   {
  434.      $field_arr array();
  435.      $str_join $this->getJoinOrder$field_arr );
  436.  
  437.      if !empty$where ) )
  438.         $sqlWhere "WHERE ".$where." ";
  439.  
  440.      $str_value "";
  441.      if is_string$value_fields ) )
  442.         $str_value $value_fields;
  443.      else
  444.      if is_array$value_fields ) )
  445.         foreach $value_fields as $str_value_field )
  446.         {
  447.           if !empty$str_value ) )
  448.              $str_value .= ", ";
  449.  
  450.           $str_value .= $str_value_field;
  451.         }
  452.  
  453.      $sqlOrder "SELECT ".$primary_key.", "
  454.                           .$str_value." "
  455.                   ."FROM `".$this->join[0]->dbt_left->name."` "
  456.                      ."AS ".$this->join[0]->alias_left." "
  457.                            .$str_join
  458.                   .$sqlWhere
  459.               ."ORDER BY `".$primary_key."` ASC";
  460.  
  461.      $result $this->join[0]->dbt_left->parent->query$sqlOrderfalse$this );
  462.  
  463.  
  464.      $primary_key preg_replace(
  465.                                     "!^.+? +AS +([-_a-z0-9]+)$!is",
  466.                                     "$1"$primary_key
  467.                                  );
  468.  
  469.      while $resultArr @mysql_fetch_array$result ) )
  470.         if is_string$value_fields ) )
  471.         {
  472.            $value_fields preg_replace(
  473.                                           "!^.+? +AS +([-_a-z0-9]+)$!is",
  474.                                           "$1"$value_fields
  475.                                        );
  476.  
  477.            $datasets$resultArr[$primary_key] ][$resultArr[$value_fields];
  478.         }
  479.         else
  480.         if is_array$value_fields ) )
  481.            $datasets$resultArr[$primary_key] ][$resultArr;
  482.  
  483.      return $datasets;
  484.   }
  485.  
  486.  
  487.  
  488.   /**
  489.    * Returns a array of values of a data field.
  490.    *
  491.    * @version 1.1
  492.    * @since   0.1.6
  493.    * @author  Daniel Plücken <daniel@debakel.net>
  494.    * @access  public
  495.    * @param   string  $fieldname 
  496.    * @param   string  $where 
  497.    * @return  array 
  498.    */
  499.   function getArrayOfDataField$fieldname$where "1=1")
  500.   {
  501.      $field_arr array ();
  502.      $str_join $this->getJoinOrder$field_arr );
  503.  
  504.      $sqlOrder  "   SELECT ".$fieldname." \r\n"
  505.                  ."     FROM `".$this->join[0]->dbt_left->name."` "
  506.                         ."AS ".$this->join[0]->alias_left." \r\n"
  507.                               .$str_join
  508.                  ."    WHERE ".$this->getCorrectWhere$where );
  509.  
  510.      $result $this->join[0]->dbt_left->parent->query$sqlOrder );
  511.  
  512.      $tmp_arr array();
  513.      while $tmp_row @mysql_fetch_row$result ) )
  514.            $tmp_arr[$tmp_row[0];
  515.  
  516.      return $tmp_arr;
  517.   }
  518.  
  519.  
  520.  
  521.   /**
  522.    * Returns the datasets as an two dimensional array if the query could be
  523.    * execute. The first dimension carries the datasets. The second dimension
  524.    * carries the fields's values of the result list.
  525.    *
  526.    * Usage:
  527.    *          getDatasetsWithFields( $fieldnamesArr, $where, $only_one );
  528.    *
  529.    * @version 1.2
  530.    * @since   0.1.42
  531.    * @author  Daniel Plücken <daniel@debakel.net>
  532.    * @access  public
  533.    * @param   array   $field_arr  Is a blind parameter whithout any funktion.
  534.    * @param   string  $where      The where clause of the query.
  535.    * @param   boolean $only_one 
  536.    * @param   string  $array_kind The kind how the tuples should be output.
  537.    *                               MYSQL_OUTPUT_ASSOC - to get an associative
  538.    *                               array, with the fieldnames as indices.
  539.    *                               MYSQL_OUTPUT_NUM - to get an array, with
  540.    *                               numbers as indices in order of the
  541.    *                               $fieldnamesArr or of the underlying table.
  542.    *                               MYSQL_OUTPUT_DEFAULT - to get a mix of both
  543.    *                               output kinds.
  544.    * @return  array 
  545.    */
  546.   function getDatasetsWithFields(
  547.                          $field_arr array(),
  548.                          $where "1=1",
  549.                          $only_one false,
  550.                          $array_kind MYSQL_OUTPUT_DEFAULT
  551.                                 )
  552.   {
  553.      $blind_arr array();
  554.      $str_join $this->getJoinOrder$blind_arr );
  555.  
  556.      $sqlOrder  "SELECT ".implode", "$field_arr )." "
  557.                    ."FROM `".$this->join[0]->dbt_left->name."` "
  558.                      ."AS ".$this->join[0]->alias_left." "
  559.                            .$str_join;
  560.  
  561.      $sqlOrder .= " WHERE ".$this->getCorrectWhere$where );
  562.  
  563.      $result $this->join[0]->dbt_left->parent->query$sqlOrder );
  564.  
  565.      $this->last_query = $sqlOrder;
  566.      $err   mysql_error();
  567.      $errno mysql_errno();
  568.  
  569.  
  570.      if (
  571.           $result
  572.        && $only_one
  573.         )
  574.      {
  575.         if $array_kind == MYSQL_OUTPUT_ASSOC // MYSQL_OUTPUT_ASSOC
  576.            return @mysql_fetch_assoc$result );
  577.         elseif $array_kind == MYSQL_OUTPUT_NUM // MYSQL_OUTPUT_NUM
  578.            return @mysql_fetch_row$result );
  579.         else // MYSQL_OUTPUT_DEFAULT
  580.            return @mysql_fetch_array$result );
  581.      }
  582.      else
  583.      if $result )
  584.      {
  585.         $i 0;
  586.         $dataset_arr array();
  587.         if $array_kind == MYSQL_OUTPUT_ASSOC // MYSQL_OUTPUT_ASSOC
  588.         while $result_arr @mysql_fetch_assoc$result ) )
  589.         {
  590.            $dataset_arr[$iarray();
  591.            $dataset_arr[$i++$result_arr;
  592.         }
  593.         elseif $array_kind == MYSQL_OUTPUT_NUM // MYSQL_OUTPUT_NUM
  594.         while $result_arr @mysql_fetch_row$result ) )
  595.         {
  596.            $dataset_arr[$iarray();
  597.            $dataset_arr[$i++$result_arr;
  598.         }
  599.         else // MYSQL_OUTPUT_DEFAULT
  600.         while $result_arr @mysql_fetch_array$result ) )
  601.         {
  602.            $dataset_arr[$iarray();
  603.            $dataset_arr[$i++$result_arr;
  604.         }
  605.  
  606.         return $dataset_arr;
  607.      }
  608.      else
  609.      {
  610.          if (
  611.               // looking for callback function of the database host object.
  612.               !empty$this->join[0]->dbt_left->parent->parent->error_callback )
  613.            && function_exists(
  614.                  $this->join[0]->dbt_left->parent->parent->error_callback
  615.                              )
  616.            && in_array(
  617.                         $errno,
  618.                         array(
  619.                                 // no connection
  620.                                 2013,
  621.                                 // Access denied for user
  622.                                 1045,
  623.                                 // no such database
  624.                                 1049
  625.                              )
  626.                       )
  627.             )
  628.          {
  629.              $tmp_name $this->join[0]->dbt_left
  630.                          ->parent->parent->error_callback;
  631.              $tmp_name$errno$err );
  632.          }
  633.          else
  634.          if (
  635.               !empty$this->error_callback )
  636.            && function_exists$this->error_callback )
  637.             )
  638.          {
  639.              $tmp_name $this->error_callback;
  640.              $tmp_name$errno$err );
  641.          }
  642.          else
  643.          if(
  644.              defined"DEBUG" )
  645.           || MYSQLDEBUGGING
  646.            )
  647.          {
  648.            echo "<pre>\r\n";
  649.            echo "<b>An error occurs!</b>\r\n";
  650.            echo "<b>BACKTRACE DEBUG:</b>\r\n";
  651.            $debugArr debug_backtrace();
  652.            print_r$debugArr[count($debugArr)-1);
  653.            echo "</pre>\r\n";
  654.            echo "<br />\r\n";
  655.            echo "<b>MySQL says:</b><br />\r\n";
  656.            echo mysql_error()."<br /><br />\r\n";
  657.            echo "<b>Your query is:</b><br />\r\n";
  658.            die$sqlOrder."<br />" );
  659.          }
  660.      }
  661.   }
  662.  
  663.  
  664.  
  665.   /**
  666.    * Returns a single dataset as an array if the query could be execute.
  667.    * Notice that the fieldnames will be output in the special form that the
  668.    * given alias of a table and the responsed fieldname are separated by an
  669.    * underscore, for example "alias_fieldname".
  670.    *
  671.    * @version 1.2
  672.    * @since   0.1.0
  673.    * @author  Daniel Plücken <daniel@debakel.net>
  674.    * @access  public
  675.    * @param   string  $fields_or_where 
  676.    * @param   string  $where 
  677.    * @param   string  $array_kind The kind how the tuples should be output.
  678.    *                               MYSQL_OUTPUT_ASSOC - to get an associative
  679.    *                               array, with the fieldnames as indices.
  680.    *                               MYSQL_OUTPUT_NUM - to get an array, with
  681.    *                               numbers as indices in order of the
  682.    *                               $fieldnamesArr or of the underlying table.
  683.    *                               MYSQL_OUTPUT_DEFAULT - to get a mix of both
  684.    *                               output kinds.
  685.    * @return  array 
  686.    */
  687.   function getSingleDataset(
  688.                              $fields_or_where,
  689.                              $where "",
  690.                              $array_kind MYSQL_OUTPUT_DEFAULT
  691.                            )
  692.   {
  693.     if is_array$fields_or_where ) )
  694.        return $this->getDatasetsWithFields(
  695.                                      $fields_or_where,
  696.                                      $wheretrue,
  697.                                      $array_kind
  698.                                           );
  699.     else
  700.     {
  701.         $field_arr array();
  702.         $str_join $this->getJoinOrder$field_arr );
  703.         $field_arr array_merge$field_arr$this->custom_field_arr );
  704.  
  705.         return $this->getDatasetsWithFields(
  706.                                      $field_arr,
  707.                                      $fields_or_where,
  708.                                      true,
  709.                                      $array_kind
  710.                                            );
  711.     }
  712.   }
  713.  
  714.  
  715.  
  716.   /**
  717.    * Returns a single value of a data field.
  718.    *
  719.    * @version 1.0
  720.    * @since   0.1.7
  721.    * @author  Daniel Plücken <daniel@debakel.net>
  722.    * @access  public
  723.    * @param   string  $fieldname 
  724.    * @param   string  $where 
  725.    * @return  mixed 
  726.    */
  727.   function getSingleDataFieldValue$fieldname$where "1=1" )
  728.   {
  729.      $tmp_row $this->getDatasetsWithFields(
  730.                                   array$fieldname )$wheretrue
  731.                                             );
  732.  
  733.      return $tmp_row[0];
  734.   }
  735.  
  736.  
  737.  
  738.   /**
  739.    * Returns the sum value of a field.
  740.    *
  741.    * @version 1.0
  742.    * @since   0.1.9
  743.    * @author  Daniel Plücken <daniel@debakel.net>
  744.    * @access  public
  745.    * @param   string $fieldname 
  746.    * @param   string $where                 The where-clause is optional.
  747.    * @param   string $additional_arithmetic Additional calculations to the
  748.    *                                         sum.
  749.    * @return  integer 
  750.    */
  751.   function getSumOf$fieldname$where "1=1"$additional_arithmetic "" )
  752.   {
  753.     if empty$where ) )
  754.        $where "1=1";
  755.  
  756.     $blind_arr array();
  757.     $sqlOrder "SELECT SUM( ".$fieldname." )"
  758.                        .$additional_arithmetic." "
  759.                  ."FROM `".$this->join[0]->dbt_left->name."` "
  760.                    ."AS ".$this->join[0]->alias_left." \r\n"
  761.                          .$this->getJoinOrder$blind_arr )
  762.                ." WHERE ".$this->getCorrectWhere$where );
  763.  
  764.     $res $this->join[0]->dbt_left->parent->query$sqlOrderfalse$this );
  765.  
  766.     $this->last_query = $sqlOrder;
  767.     $resArr mysql_fetch_row$res );
  768.  
  769.     return $resArr[0];
  770.   }
  771.  
  772.  
  773.  
  774.   /**
  775.    * Returns the count of datasets.
  776.    *
  777.    * @version 1.3
  778.    * @since   0.1.2
  779.    * @author  Daniel Plücken <daniel@debakel.net>
  780.    * @access  public
  781.    * @param   string $where 
  782.    * @param   string $fieldname 
  783.    * @return  integer 
  784.    */
  785.   function getCount$where "1=1"$fieldname "*" )
  786.   {
  787.     $blind_arr array();
  788.     $sqlOrder  "SELECT count(".$fieldname.") "
  789.                   ."FROM `".$this->join[0]->dbt_left->name."` "
  790.                     ."AS ".$this->join[0]->alias_left." "
  791.                              .$this->getJoinOrder$blind_arr )
  792.                 ." WHERE ".$this->getCorrectWhere$where );
  793.  
  794.     $res $this->join[0]->dbt_left->parent->query$sqlOrderfalse$this );
  795.     $this->last_query = $sqlOrder;
  796.     $resArr mysql_fetch_row$res );
  797.  
  798.     return $resArr[0];
  799.   }
  800. // End of class MySQLView
  801. ?>

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