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

Source for file Database.class.php

Documentation is available at Database.class.php

  1. <?php
  2. /**
  3.  * @package databases
  4.  */
  5.  
  6. /**
  7.  * @package   databases
  8.  * @version   0.1.44
  9.  * @author    Daniel Plücken <daniel@debakel.net>
  10.  * @license   http://www.gnu.org/copyleft/lesser.html
  11.  *             GNU Lesser General Public License
  12.  * @copyright Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  13.  *
  14.  *  This library is free software; you can redistribute it and/or
  15.  *  modify it under the terms of the GNU Lesser General Public
  16.  *  License as published by the Free Software Foundation; either
  17.  *  version 2.1 of the License.
  18.  *
  19.  *  This library is distributed in the hope that it will be useful,
  20.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22.  *  GNU Lesser General Public License for more details.
  23.  *
  24.  *  You should have received a copy of the GNU Lesser General
  25.  *  Public License along with this library; if not, write to the
  26.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  27.  *  Boston, MA 02111-1307 USA
  28.  */
  29. class Database
  30. {
  31.   /**
  32.    * The name of this database.
  33.    *
  34.    * @var    string  $name 
  35.    * @access public
  36.    */
  37.   var $name;
  38.   /**
  39.    * Carries the databasetable's objects of this database.
  40.    *
  41.    * @var    array   $dbt 
  42.    * @access private
  43.    */
  44.   var $dbt;
  45.   /**
  46.    * Carryies the view's objects of this database.
  47.    *
  48.    * @var    array   $view 
  49.    * @access private
  50.    */
  51.   var $view;
  52.   /**
  53.    * Refers to the databasehost in which this database lies.
  54.    *
  55.    * @var    object  $parent 
  56.    * @access public
  57.    */
  58.   var $parent;
  59.   /**
  60.    * The last stored databasequery.
  61.    *
  62.    * @var    string  $last_query 
  63.    * @access public
  64.    */
  65.   var $last_query;
  66.   /**
  67.    * Carries the name of a function which has to be invoked on a connection
  68.    * error.
  69.    *
  70.    * @access public
  71.    * @var    function $error_callback 
  72.    */
  73.   var $error_callback = null;
  74.  
  75.  
  76.  
  77.   /**
  78.     * Constructor
  79.     *
  80.     * @version 1.1
  81.     * @since   0.1.0
  82.     * @author  Daniel Plücken <daniel@debakel.net>
  83.     * @access  public
  84.     * @param   string $name 
  85.     * @param   object $parent 
  86.     */
  87.   function Database$name$parent "" )
  88.   {
  89.     if !empty$name ) )
  90.     {
  91.        $this->name = $name;
  92.        $this->parent = $parent;
  93.     }
  94.     else
  95.        die(
  96.             "<h3>You have to give a name to this database!</h3>"
  97.            ."<b>Use following Syntax:<b><br><br>\r\n"
  98.            ."<pre>\r\n"
  99.            ."  \x24db = new Database( \x24name );\r\n"
  100.            ."</pre>\r\n"
  101.           );
  102.   }
  103.  
  104.  
  105.  
  106.   /**
  107.    * Sets the name of the function that should be invoked on a connection error.
  108.    * The function to call back has to have two parameter. The first parameter is
  109.    * for the error code. The second one contains the errordescription.
  110.    *
  111.    * @version 1.0
  112.    * @since   0.1.43
  113.    * @author  Daniel Plücken <daniel@debakel.net>
  114.    * @access  public
  115.    * @param   string $function_name_str 
  116.    * @return  void 
  117.    */
  118.   function setErrorCallback$function_name_str )
  119.   $this->error_callback = $function_name_str}
  120.  
  121.  
  122.  
  123.   /**
  124.    * Adds a databasetable's reference to this object of a database.
  125.    *
  126.    * @version 1.1
  127.    * @since   0.1.0
  128.    * @author  Daniel Plücken <daniel@debakel.net>
  129.    * @access  public
  130.    * @param   object  $dbt_obj 
  131.    */
  132.   function addDBT&$dbt_obj )
  133.   {
  134.     if(
  135.         !function_exists"is_a" )
  136.      && (
  137.           get_class$dbt_obj == "abstdatabasetable"
  138.        || get_parent_class$dbt_obj == "abstdatabasetable"
  139.         )
  140.       )
  141.     {
  142.       $dbt_obj->setParent$this );
  143.       $this->dbt[$dbt_obj;
  144.     }
  145.     else
  146.     if(
  147.         function_exists"is_a" )
  148.      && (
  149.           is_a$dbt_obj"ABSTDatabaseTable" )
  150.        || is_subclass_of$dbt_obj"ABSTDatabaseTable" )
  151.         )
  152.       )
  153.     {
  154.       $dbt_obj->setParent$this );
  155.       $this->dbt[$dbt_obj;
  156.     }
  157.     else
  158.       die(
  159.            "<h3>The parameter does not refer to "
  160.               ."a valid object of a databasetable!</h3>"
  161.          );
  162.   }
  163.  
  164.  
  165.  
  166.   /**
  167.    * Adds a view's reference to this object of a database.
  168.    *
  169.    * @version 1.1
  170.    * @since   0.1.2
  171.    * @author  Daniel Plücken <daniel@debakel.net>
  172.    * @access  public
  173.    * @param   object  $view_obj 
  174.    */
  175.   function addView&$view_obj )
  176.   {
  177.     if(
  178.         !function_exists"is_a" )
  179.      && (
  180.           get_class$view_obj == "view"
  181.        || get_parent_class$view_obj == "view"
  182.         )
  183.       )
  184.       $this->view[$view_obj;
  185.     else
  186.     if(
  187.         function_exists"is_a" )
  188.      && (
  189.           is_a$view_obj"View" )
  190.        || is_subclass_of$view_obj"view" )
  191.         )
  192.       )
  193.       $this->view[$view_obj;
  194.     else
  195.       die(
  196.            "<h3>The parameter does not refer to "
  197.               ."a valid object of a database view!</h3>"
  198.          );
  199.   }
  200.  
  201.  
  202.  
  203.   /**
  204.    * Returns the array of references to the databasetables.
  205.    *
  206.    * @version 1.0
  207.    * @since   0.1.0
  208.    * @author  Daniel Plücken <daniel@debakel.net>
  209.    * @access  public
  210.    * @return  string 
  211.    */
  212.   function &getDatabaseTables ()
  213.   return $this->dbt}
  214.  
  215.  
  216.  
  217.   /**
  218.    * Returns the array of references to the views.
  219.    *
  220.    * @version 1.0
  221.    * @since   0.1.2
  222.    * @author  Daniel Plücken <daniel@debakel.net>
  223.    * @access  public
  224.    * @return  string 
  225.    */
  226.   function &getViews ()
  227.   return $this->view}
  228.  
  229.  
  230.  
  231.    /**
  232.    * Returns the databasename.
  233.    *
  234.    * @version 1.0
  235.    * @since   0.1.0
  236.    * @author  Daniel Plücken <daniel@debakel.net>
  237.    * @access  public
  238.    * @return  string 
  239.    */
  240.   function getDatabase()
  241.   return $this->name}
  242.  
  243.  
  244.  
  245.   /**
  246.    * Returns the databasename. This method is an alias for the method
  247.    * getDatabase()
  248.    *
  249.    * @version 1.0
  250.    * @author  Daniel Plücken <daniel@debakel.net>
  251.    * @access  public
  252.    * @return  string 
  253.    */
  254.   function getName()
  255.   return $this->name}
  256.  
  257.  
  258.  
  259.   /**
  260.    * Returns the last stored database query.
  261.    *
  262.    * @version 1.0
  263.    * @since   0.1.3
  264.    * @author  Daniel Plücken <daniel@debakel.net>
  265.    * @access  public
  266.    * @return  array 
  267.    */
  268.   function getLastQuery()
  269.   return $this->last_query}
  270.  
  271.  
  272.  
  273.   /**
  274.    * Sets the parent of this object.
  275.    *
  276.    * @version 1.2
  277.    * @since   0.1.1
  278.    * @author  Daniel Plücken <daniel@debakel.net>
  279.    * @access  public
  280.    * @param   object 
  281.    * @return  void 
  282.    */
  283.   function setParent&$obj_ref )
  284.   {
  285.     if(
  286.         !function_exists"is_a" )
  287.      && (
  288.           get_class$obj_ref == "abstdatabasehost"
  289.        || get_parent_class$obj_ref == "abstdatabasehost"
  290.         )
  291.       )
  292.       $this->parent = &$obj_ref;
  293.     else
  294.     if(
  295.         function_exists"is_a" )
  296.      && (
  297.           is_a$obj_ref"ABSTDatabaseHost" )
  298.        || is_subclass_of$obj_ref"ABSTDatabaseHost" )
  299.         )
  300.       )
  301.       $this->parent = &$obj_ref;
  302.     else
  303.       die(
  304.            "<h3>The given parameter is not a reference "
  305.               ."of an object of a databasehost!</h3>"
  306.          );
  307.   }
  308.  
  309.  
  310.  
  311.   /**
  312.    * Returns the id of the connection resource to the database host.
  313.    *
  314.    * @access  public
  315.    * @version 1.0
  316.    * @since   0.1.44
  317.    *
  318.    * @return object 
  319.    */
  320.   function &getResourceID()
  321.   return $this->parent->getResourceID()}
  322. // End of class Database
  323. ?>

Documentation generated on Thu, 05 Jun 2008 19:10:33 +0200 by phpDocumentor 1.4.1