Source for file Database.php
Documentation is available at Database.php
* A Framework for Creating and Using Complex Web Elements
* The purpose of this framework is to provide a library of high-level objects
* to facilitate common HTML coding tasks, such as menus, tables, and forms.
* The intent is to reduce repetitive HTML coding as much as possible, replacing
* it with a combination of configuration files and style sheets with
* standardized naming conventions.
* This framework is built on and requires the
* {@link http://framework.zend.com/ Zend Framework}.
* @author Lyle Frost <lfrost@cnz.com>
* @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
* @license http://www.citadelnetwork.com/license/cnzframework New BSD License
* @version $Id: Database.php 27 2007-07-19 18:47:54Z lfrost $
Zend_Loader::loadClass('Cnz_Html_Table');
Zend_Loader::loadClass('Zend_Filter');
Zend_Loader::loadClass('Zend_Filter_Alnum');
Zend_Loader::loadClass('Zend_Db_Select');
* HTML Table Database class
private $filterArray = array();
private $joinArray = array();
/* Getters/Setters ===================================================*/
/** @return string Query */
* @param string $query New query
/* Methods ===========================================================*/
* @param array $options Options
* @param Zend_Config $config Configuration
// Process configuration.
if (isset ($this->config->cols)) $this->columns = $this->config->cols;
if (isset ($this->config->from)) $this->from = $this->config->from;
if (isset ($this->config->join))
for ($this->config->join->rewind(); $this->config->join->valid(); $this->config->join->next())
$joinConfig = $this->config->join->current();
$join['name'] = $this->config->join->key();
if (isset ($joinConfig->type)) $join['type'] = $joinConfig->type;
// HACK: Zend_Config_Ini does not allow " in values.
if (isset ($joinConfig->on)) $join['on'] = str_replace('`', '"', $joinConfig->on);
if (isset ($joinConfig->columns)) $join['columns'] = explode(',', $joinConfig->columns);
$this->joinArray[] = $join;
* @return boolean Success
if (strlen($column->getExpression()) < 1)
$columns[] = $column->getName();
$columns[] = new Zend_Db_Expr($column->getExpression() . ' AS ' . $column->getName());
// Primary key (change to be configurable)
$select->from($this->from, $columns)
foreach ($this->joinArray as $join)
$select->join($join['name'], $join['on'], $join['columns']);
foreach ($this->filterArray as $key => $value)
$select->where($key . ' = ?', $_POST[$key]);
$this->query = $select->__toString();
$result = $db->query('SELECT count(*) FROM ' . $db->quoteIdentifier($this->from));
$rowSet = $result->fetchAll();
$this->rowCount = (int) $rowSet[0]['count'];
$result = $db->query($this->query);
$result->setFetchMode(Zend_Db::FETCH_ASSOC);
|