Source for file MDB.php
Documentation is available at MDB.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* A framework for authentication and authorization in PHP applications
* LiveUser_Admin is meant to be used with the LiveUser package.
* It is composed of all the classes necessary to administrate
* You'll be able to add/edit/delete/get things like:
* And all other entities within LiveUser.
* At the moment we support the following storage containers:
* But it takes no time to write up your own storage container,
* so if you like to use native mysql functions straight, then it's possible
* to do so in under a hour!
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* @category authentication
* @package LiveUser_Admin
* @author Markus Wolff <wolff@21st.de>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @author Lukas Smith <smith@pooteeweet.org>
* @author Arnaud Limbourg <arnaud@php.net>
* @author Christian Dickmann <dickmann@php.net>
* @author Matt Scifo <mscifo@php.net>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id: MDB.php 213700 2006-05-25 08:20:34Z lsmith $
* @link http://pear.php.net/LiveUser_Admin
* Require parent class definition.
require_once 'LiveUser/Admin/Storage/SQL.php';
* This is a PEAR::MDB backend driver for the LiveUser class.
* A PEAR::MDB connection object can be passed to the constructor to reuse an
* existing connection. Alternatively, a DSN can be passed to open a new one.
* - File "Liveuser/Admin.php" (contains the parent class "LiveUser_Admin")
* - Array of connection options or a PEAR::MDB connection object must be
* passed to the init() method
* Example: array('dsn' => 'mysql://user:pass@host/db_name')
* array('dbc' => &$conn) ($conn is a PEAR::MDB connection object)
* @category authentication
* @package LiveUser_Admin
* @author Lukas Smith <smith@pooteeweet.org>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version Release: @package_version@
* @link http://pear.php.net/LiveUser_Admin
* Database connection functions
var $function = 'connect';
* Initializes database storage container.
* Connects to database or uses existing database connection.
* @param array Storage Configuration
* @param array containing the database structure (tables, fields, alias)
* @return bool true on success and false on failure
function init(&$storageConf, $structure)
parent ::init ($storageConf, $structure);
if (!MDB ::isConnection ($this->dbc) && !is_null($this->dsn)) {
$this->options['optimize'] = 'portability';
if ($this->function == 'singleton') {
$dbc = & MDB ::singleton ($this->dsn, $this->options);
$dbc = & MDB ::connect ($this->dsn, $this->options);
if (PEAR ::isError ($dbc)) {
$this->stack->push (LIVEUSER_ERROR_INIT_ERROR , 'error',
array ('container' => 'could not connect: '. $dbc->getMessage (),
'debug' => $dbc->getUserInfo ()));
if (!MDB ::isConnection ($this->dbc)) {
$this->stack->push (LIVEUSER_ERROR_INIT_ERROR , 'error',
array ('container' => 'storage layer configuration missing'));
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string text string value that is intended to be converted.
* @param string type to which the value should be converted to
* @return stringtext string that represents the given argument value in
* a DBMS specific format.
function quote($value, $type)
return $this->dbc->getValue ($type, $value);
* Apply a type to all values of an array and return as a comma
* seperated string useful for generating IN statements
* @param array data array
* @param string determines type of the field
* @return string comma seperated values
if (!is_array($array) || empty ($array)) {
foreach ($array as $value) {
$return[] = $this->dbc->getValue ($type, $value);
* Sets the range of the next query
* @param string number of rows to select
* @param string first row to select
* @return bool true on success and false on failure
* @uses MDB::setSelectedRowRange
$result = $this->dbc->setSelectedRowRange ($offset, $limit);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* @param string DML query
* @return bool|intof the affected rows
* @uses MDB::query MDB::affectedRows
$result = $this->dbc->query ($query);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
return $this->dbc->affectedRows ();
* Execute the specified query, fetch the value from the first column of
* the first row of the result set and then frees the result set.
* @param string the SELECT query statement to be executed.
* @param string argument that specifies the expected datatype of the
* result set field, so that an eventual conversion may be performed.
* The default datatype is text, meaning no conversion is performed.
$result = $this->dbc->queryOne ($query, $type);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* Execute the specified query, fetch the values from the first
* row of the result set into an array and then frees
* @param string the SELECT query statement to be executed.
* @param array argument that specifies a list of expected datatypes
* of theresult set columns, so that the conversions may be performed.
* The default datatype is text, meaning no conversion is performed.
$result = $this->dbc->queryRow ($query, $type, MDB_FETCHMODE_ASSOC );
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* Execute the specified query, fetch the value from the first column of
* each row of the result set into an array and then frees the result set.
* @param string the SELECT query statement to be executed.
* @param string argument that specifies the expected datatype of the
* result set field, so that an eventual conversion may be performed.
* The default datatype is text, meaning no conversion is performed.
$result = $this->dbc->queryCol ($query, $type);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* Execute the specified query, fetch all the rows of the result set into
* a two dimensional array and then frees the result set.
* @param string the SELECT query statement to be executed.
* @param array argument that specifies a list of expected datatypes
* of theresult set columns, so that the conversions may be performed.
* The default datatype is text, meaning no conversion is performed.
* @param bool if set to true, returned array will have the first
* column as its first dimension
* @param bool if set to true and $rekey is set to true, then
* all values with the same first column will be wrapped in an array
function queryAll($query, $types, $rekey, $group)
$result = $this->dbc->queryAll ($query, $types, MDB_FETCHMODE_ASSOC , $rekey, false , $group);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* returns the next free id of a sequence
* @param string name of the sequence
* @param bool when true the seqence is
* automatic created, if it not exists
* @return bool|intfalse on failure or next id for the table
function nextId($seqname, $ondemand = true )
$result = $this->dbc->nextId ($seqname, $ondemand);
if (PEAR ::isError ($result)) {
array ('reason' => $result->getMessage () . '-' . $result->getUserInfo ())
* Since MDB does not support determining if auto increment is supported,
* the call is redirected to nextID()
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @param bool when true the seqence is automatic created, if it not exists
* @uses MDB2::nextId MDB2_Extended::getBeforeId
$seq = $table. (empty ($field) ? '' : '_'. $field);
return $this->nextId($seq, $ondemand);
* Since MDB does not support determining if auto increment is supported,
* the call just returns the $id parameter
* @param string value as returned by getBeforeId()
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @return bool|intreturns the id that the users passed via params
* @uses MDB2_Extended::getAfterId
Documentation generated on Tue, 05 Oct 2010 16:30:10 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|