Source for file Db.class.php

Documentation is available at Db.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Debug
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Debug DB Report Class
  22.  *
  23.  * @category Gumbo
  24.  * @package Debug
  25.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  26.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  27.  * @author Michael Luster <mluster79@yahoo.com>
  28.  * @link http://sourceforge.net/projects/phpgumbo
  29.  * @desc Debug DB Report Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Debug_Report");
  34. gumbo_load ("Date");
  35. gumbo_load ("Query");
  36.  
  37.  
  38.     /** @var string $_db Debug Report Database */
  39.     private $_db;
  40.  
  41.  
  42.  
  43.     /**
  44.      * Constructor
  45.      * @param string $db database table name
  46.      */
  47.     public function __construct ($db=null{
  48.         if (defined ("GUMBO_DEBUG_DB")) $this->setDb (GUMBO_DEBUG_DB)}
  49.         if (!is_null ($db)) $this->setDb ($db)}
  50.     }
  51.  
  52.  
  53.  
  54.     /** ACTION METHODS **/
  55.     /**
  56.      * Runs the Report
  57.      * @param num $start_time initial start time of script debugger
  58.      * @throws Gumbo_Exception
  59.      * @uses Gumbo_Date, Gumbo_Query
  60.      */
  61.     public function run ($start_time=null{
  62.         try {
  63.             // verify precondition
  64.             if (!$this->getDb ()) {
  65.                 throw new Gumbo_Exception ("Debug Database Undefined");
  66.             }
  67.             
  68.             $date new Gumbo_Date ();
  69.             foreach ($this->getMessages (as $mess{
  70.                 $mess->setSeconds ($start_time);
  71.                 
  72.                 $sql "insert into " $this->getDb (" " 
  73.                         "(date, time, message, file, line, func, cls) values " .
  74.                         "({$date->get ()}, {$mess->getSeconds ()}, {$this->getMessage ()}
  75.                         "{$this->getFile ()}, {$this->getLine ()}, {$this->getFunction ()}, {$this->getClass ()})";
  76.                 
  77.                 Gumbo_Query::execute ($sql);
  78.                 
  79.                 $start_time $mess->getTime ();
  80.             }
  81.         catch (Gumbo_Exception $e{
  82.             $e->setFunction (__METHOD__);
  83.             gumbo_trigger ($e);
  84.         }
  85.     }
  86.  
  87.  
  88.  
  89.     /** MUTATOR METHODS **/
  90.     /**
  91.      * Sets the Debug Database
  92.      * @param string $db 
  93.      * @throws Gumbo_Exception
  94.      */
  95.     public function setDb ($db{
  96.         try {
  97.             // verify precondition
  98.             if (!is_string ($db)) {
  99.                 throw new Gumbo_Exception ("Invalid Argument 'db:str' => {$db}:gettype ($db));
  100.             }
  101.             
  102.             $this->_db = $db;
  103.         catch (Gumbo_Exception $e{
  104.             $e->setFunction (__METHOD__);
  105.             gumbo_trigger ($e);
  106.         }
  107.     }
  108.  
  109.  
  110.  
  111.     /** ACCESSOR METHODS **/
  112.     /**
  113.      * Returns the Debug Database
  114.      * @return string 
  115.      */
  116.     public function getDb ({
  117.         return $this->_db;
  118.     }
  119.  
  120. }
  121.  
  122. ?>