Source for file libdb.php
Documentation is available at libdb.php
* Database abstraction layer class and functions.
* @author Christopher Troup <mini@chatetheory.com>
@include_once dirname(__FILE__ ) . '/../conf/conf.php';
* Data abstraction layer class.
* @var MDB2_Database_Object
private $connected = false;
* Initiate a connection to the database
if ($this->connected == false) {
$dsn = $conf['dbDriver'] . '://' . $conf['mysqlUsername'] . ':' .
$conf['mysqlPassword'] . '@' . $conf['mysqlHost'] . ':' .
$conf['mysqlPort'] . '/' . $conf['mysqlDbName'];
$this->_db = & MDB2 :: connect($dsn);
if (PEAR :: isError($this->_db)) {
$this->connected = false;
throw new Exception($this->_db->toString());
* Preform a database query
* @param string $sql The SQL statement to preform
* @return array Query results
if (@$memcache = new Memcache) {
if (@$memcache->connect('localhost', 11211)) {
if ( $var = $memcache->get(md5($sql))) {
if (PEAR :: isError($result = $this->_db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC))) {
throw new Exception($result->getMessage());
$this->_db->query('insert into phpusertrack_log set message=\'' . $sql . '\'');
$memcache->set(md5($sql), $result, 0, 60* 5);
* Insert data into the database
* @param string $sql SQL statement to preform
if (PEAR :: isError($result = $result = $this->_db->query($sql))) {
throw new Exception($result->getMessage());
$this->_db->query('insert into phpusertrack_log set message=\'' . $sql . '\'');
return $this->_db->lastInsertID();
|