Source for file DB.php
Documentation is available at DB.php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Jon Wood |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jon Wood <jon@jellybob.co.uk> |
// +----------------------------------------------------------------------+
// $Id: DB.php,v 1.3 2004/07/07 16:05:30 jellybob Exp $
* Require the core class.
require_once('Auth/PrefManager2/Container.php');
* Require PEAR DB for data management.
* The PEAR DB container for Auth_PrefManager2
* @author Jon Wood <jon@jellybob.co.uk>
* @package Auth_PrefManager2
* @category Authentication
* The DB object being used for data access.
return $this->_connect ();
* Sets a value with the container.
* @param string $owner The owner to set the preference for.
* @param string $preference The name of the preference to set.
* @param string $application The application to set for.
* @return bool Success/failure
function _set($owner, $preference, $value, $application)
if ($this->_exists($owner, $preference, $application)) {
// If the preference already exists update its value.
$query = sprintf('UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s AND %s=%s',
$this->_db->quoteSmart ($value),
$this->_db->quoteSmart ($owner),
$this->_db->quoteSmart ($preference),
$this->_db->quoteSmart ($application));
// Otherwise insert a new row.
$query = sprintf('INSERT INTO %s (%s, %s, %s, %s) VALUES(%s, %s, %s, %s)',
$this->_db->quoteSmart ($value),
$this->_db->quoteSmart ($owner),
$this->_db->quoteSmart ($preference),
$this->_db->quoteSmart ($application));
$result = $this->_runQuery ($query);
* Gets a value from the container.
* @param string $owner The owner to set the preference for.
* @param string $preference The name of the preference to set.
* @param mixed $value The value to set the preference to.
* @param string $application The application to set for.
* @return mixed|nullThe value, or null if none is set.
function _get($owner, $preference, $application)
if ($this->_exists($owner, $preference, $application)) {
// If the preference already exists update its value.
$query = sprintf('SELECT %s FROM %s WHERE %s=%s AND %s=%s AND %s=%s',
$this->_db->quoteSmart ($owner),
$this->_db->quoteSmart ($preference),
$this->_db->quoteSmart ($application));
$result = $this->_runQuery ($query);
$row = $result->fetchRow ();
* Deletes a value from the container.
* @param string $owner The owner to delete the preference for.
* @param string $preference The name of the preference to delete.
* @param string $application The application to delete from.
* @return bool Success/failure
function _delete($owner, $preference, $application)
if ($this->_exists($owner, $preference, $application)) {
// If the preference already exists update its value.
$query = sprintf('DELETE FROM %s WHERE %s=%s AND %s=%s AND %s=%s',
$this->_db->quoteSmart ($owner),
$this->_db->quoteSmart ($preference),
$this->_db->quoteSmart ($application));
// Should this be returning true, since the value is no longer
// there, or false, because no delete has been done?
$result = $this->_runQuery ($query);
* Checks if the specified preference exists in the data container.
* Returns null if an error occurs.
* @param string $owner The owner to delete the preference for.
* @param string $preference The name of the preference to delete.
* @param string $application The application to delete from.
* @return bool Does the pref exist?
function _exists($owner, $preference, $application)
$query = sprintf('SELECT COUNT(%s) FROM %s WHERE %s=%s AND %s=%s AND %s=%s',
$this->_db->quoteSmart ($owner),
$this->_db->quoteSmart ($preference),
$this->_db->quoteSmart ($application));
$result = $this->_runQuery ($query);
$count = $result->fetchRow ();
* Connects to the DSN provided in the options array.
* @return bool Success/failure
* @throws AUTH_PREFMANAGER2_DB_CONNECTION_FAILED
$db = & DB ::connect ($this->_options['dsn']);
if (PEAR ::isError ($db)) {
* Runs a query on the database.
* @param string $query The query to run.
* @return DB_Result|nullThe result object for the query.
* @throws AUTH_PREFMANAGER2_DB_QUERY_FAILED
* @todo Improve the connection handling here.
function &_runQuery ($query)
$result = $this->_db->query ($query);
if (DB ::isError ($result)) {
* Reads the options array, and sets default values for anything
* @param array $options An array of options.
if (!isset ($options['table'])) {
$options['table'] = 'preferences';
if (!isset ($options['owner_column'])) {
$options['owner_column'] = 'owner';
if (!isset ($options['application_column'])) {
$options['application_column'] = 'application';
if (!isset ($options['preference_column'])) {
$options['preference_column'] = 'name';
if (!isset ($options['value_column'])) {
$options['value_column'] = 'value';
if (!isset ($options['dsn'])) {
Documentation generated on Mon, 11 Mar 2019 13:54:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|