Source for file DBLite.php
Documentation is available at DBLite.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | 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: Martin Jansen <mj@php.net> |
// +----------------------------------------------------------------------+
// $Id: DBLite.php,v 1.2 2004/07/02 22:42:00 yavo Exp $
require_once 'Auth/Container.php';
* A lighter storage driver for fetching login data from a database
* This driver is derived from the DB storage container but
* with the user manipulation function removed for smaller file size
* by the PEAR DB abstraction layer to fetch login data.
* @author Martin Jansen <mj@php.net>
* @version $Revision: 1.2 $
* Additional options for the storage container
* User that is currently selected from the DB.
* Constructor of the container class
* Initate connection to the database via PEAR::DB
* @param string Connection data or DB object
* @return object Returns an error object if something went wrong
$this->options['usernamecol'] = 'username';
$this->options['passwordcol'] = 'password';
$this->options['cryptType'] = 'md5';
$this->options['db_options'] = array ();
$this->_parseOptions ($dsn);
if (empty ($this->options['dsn'])) {
PEAR ::raiseError ('No connection parameters specified!');
* Connect to database by using the given DSN string
* @param string DSN string
* @return mixed Object on error, otherwise bool
$this->db = & DB ::connect ($dsn, $this->options['db_options']);
return PEAR ::raiseError ("Invalid dsn or db object given");
if (DB ::isError ($this->db) || PEAR ::isError ($this->db)) {
return PEAR ::raiseError ($this->db->getMessage (), $this->db->getCode ());
* Prepare database connection
* This function checks if we have already opened a connection to
* the database. If that's not the case, a new connection is opened.
* @return mixed True or a DB error object.
if (!DB ::isConnection ($this->db)) {
$res = $this->_connect ($this->options['dsn']);
if (DB ::isError ($res) || PEAR ::isError ($res)) {
* Parse options passed to the container class
function _parseOptions ($array) {
foreach ($array as $key => $value) {
/* Include additional fields if they exist */
if (!empty ($this->options['db_fields'])) {
* Get user information from database
* This function uses the given username to fetch
* the corresponding login data from the database
* table. If an account that matches the passed username
* and password is found, the function returns true.
* Otherwise it returns false.
* @return mixed Error object or boolean
// Prepare for a database query
$err = $this->_prepare ();
return PEAR ::raiseError ($err->getMessage (), $err->getCode ());
// Find if db_fields contains a *, if so assume all col are selected
$sql_from = $this->options['usernamecol'] . ", ". $this->options['passwordcol']. $this->options['db_fields'];
$query = "SELECT ". $sql_from.
" WHERE ". $this->options['usernamecol']. " = '". $this->db->quoteString ($username). "'";
$res = $this->db->getRow ($query, null , DB_FETCHMODE_ASSOC );
return PEAR ::raiseError ($res->getMessage (), $res->getCode ());
// Store additional field values in the session
foreach ($res as $key => $value) {
if ($key == $this->options['passwordcol'] ||
$key == $this->options['usernamecol']) {
// Use reference to the auth object if exists
// This is because the auth session variable can change so a static call to setAuthData does not make sence
$this->_auth_obj->setAuthData ($key, $value);
Documentation generated on Mon, 11 Mar 2019 13:52:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|