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

Source for file libdb.php

Documentation is available at libdb.php

  1. <?php
  2. /**
  3.  * Database abstraction layer class and functions.
  4.  * @author Christopher Troup <mini@chatetheory.com>
  5.  * @package phpUserTrack
  6.  */
  7. //require 'libsite.php';
  8. //require 'libdata.php';
  9. //require 'libip.php';
  10. require_once 'MDB2.php';
  11. @include_once dirname(__FILE__'/../conf/conf.php';
  12.  
  13. /**
  14.  * Data abstraction layer class.
  15.  * @package phpUserTrack
  16.  * @sublass Libraries
  17.  */
  18. class phpusertrack_db {
  19.  
  20.     /**
  21.      * Database container
  22.      * @var MDB2_Database_Object
  23.      */
  24.     public $_db;
  25.     private $connected false;
  26.     
  27.     /**
  28.      * Class constructor
  29.      */
  30.     function phpusertrack_db({
  31.  
  32.     }
  33.  
  34.     /**
  35.      * Initiate a connection to the database
  36.      */
  37.     function _connect({
  38.         global $conf;
  39.         if ($this->connected == false{
  40.             $dsn $conf['dbDriver''://' $conf['mysqlUsername'':' .
  41.             $conf['mysqlPassword''@' $conf['mysqlHost'':' .
  42.             $conf['mysqlPort''/' $conf['mysqlDbName'];
  43.             $this->_db MDB2 :: connect($dsn);
  44.             if (PEAR :: isError($this->_db)) {
  45.                 $this->connected false;
  46.                 //return false;
  47.                 throw new Exception($this->_db->toString());
  48.             }
  49.             $this->connected true;
  50.         }
  51.         return true;
  52.     }
  53.  
  54.     /**
  55.      * Preform a database query
  56.      * @param string $sql The SQL statement to preform
  57.      * @return array Query results
  58.      */
  59.     function _query($sql{
  60.         if (@$memcache new Memcache{
  61.             if (@$memcache->connect('localhost'11211)) {
  62.                 $haveMemcache true;
  63.                 if $var $memcache->get(md5($sql))) {
  64.                     return $var;
  65.                 }
  66.             }
  67.         }
  68.         if (!$this->_connect()) {
  69.             return $this->_db;
  70.         }
  71.         if (PEAR :: isError($result $this->_db->queryAll($sqlnullMDB2_FETCHMODE_ASSOC))) {
  72.             throw new Exception($result->getMessage());
  73.         }
  74.         $this->_db->query('insert into phpusertrack_log set message=\'' $sql '\'');
  75.         if ($haveMemcache{
  76.             $memcache->set(md5($sql)$result060*5);
  77.         }
  78.         return $result;
  79.     }
  80.  
  81.     /**
  82.      * Insert data into the database
  83.      * @param string $sql SQL statement to preform
  84.      * @return array Result
  85.      */
  86.     function _insert($sql{
  87.         global $conf;
  88.         if (!$this->connected{
  89.           $this->_connect();
  90.         }
  91.         if (PEAR :: isError($result $result $this->_db->query($sql))) {
  92.             throw new Exception($result->getMessage());
  93.         }
  94.         $this->_db->query('insert into phpusertrack_log set message=\'' $sql '\'');
  95.         return $this->_db->lastInsertID();
  96.     }
  97.  
  98. }
  99. ?>

Documentation generated on Tue, 06 Nov 2007 09:21:59 -0800 by phpDocumentor 1.4.0a2