Source for file PDO.php
Documentation is available at PDO.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* A framework for authentication and authorization in PHP applications
* LiveUser is an authentication/permission framework designed
* to be flexible and easily extendable.
* Since it is impossible to have a
* "one size fits all" it takes a container
* approach which should enable it to
* be versatile enough to meet most needs.
* 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
* @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 Pierre-Alain Joye <pajoye@php.net>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id: PDO.php,v 1.13 2006/06/05 09:54:58 lsmith Exp $
* @link http://pear.php.net/LiveUser
* Require parent class definition.
require_once 'LiveUser/Perm/Storage/SQL.php';
* PDO container for permission handling.
* This is a PDO backend driver for the LiveUser class.
* A PDO 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.php" (contains the parent class "LiveUser")
* - Array of connection options
* passed to the constructor.
* Example: array('dsn' => 'mysql:host:localhost;dbname=db_name',
* 'options' => array('username' => 'root', 'password' => 'secret', 'attr' => array()));
* @category authentication
* @author Arnaud Limbourg <arnaud@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
* determines of the use of sequences should be forced
* Initialize the storage container
* @param array Array with the storage configuration
* @return bool true on success, false on failure.
function init(&$storageConf)
parent ::init ($storageConf);
if (!is_a($this->dbc, 'pdo') && !is_null($this->dsn)) {
$login = $password = $extra = null;
if (!empty ($this->options)) {
$login = $this->options['username'];
$password = $this->options['password'];
$extra = $this->options['attr'];
$dbc = new PDO ($this->dsn, $login, $password, $extra);
} catch (PDOException $e) {
'container' => 'could not connect: ' . $e->getMessage (),
'debug' => $e->getTrace ()
if (!is_a($this->dbc, 'pdo')) {
array ('container' => 'storage layer configuration missing'));
* map an auth user to a perm user
* @param int auth user id
* @param string name of the container
* @return array|false requested data or false on failure
function mapUser($auth_user_id, $containerName)
' . $this->alias['perm_user_id'] . ' AS perm_user_id,
' . $this->alias['perm_type'] . ' AS perm_type
' . $this->alias['auth_user_id'] . ' = '.
$this->dbc->quote ($auth_user_id). '
' . $this->alias['auth_container_name'] . ' = '.
$this->dbc->quote ((string) $containerName);
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
$row = $result->fetch (PDO ::FETCH_ASSOC );
if ($row === false && $this->dbc->errorCode () === '00000') {
* Reads all rights of current user into a
* two-dimensional associative array, having the
* area names as the key of the 1st dimension.
* Group rights and invididual rights are being merged
* @param int perm user id
* @return array requested data or false on failure
' . $this->alias['right_id'] . ',
' . $this->alias['right_level'] . '
' . $this->alias['perm_user_id'] . ' = '.
$this->dbc->quote ($perm_user_id);
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
while ($row = $result->fetch (PDO ::FETCH_NUM )) {
$rows[$row[0 ]] = $row[1 ];
* read the areas in which a user is an area admin
* @param int perm user id
* @return array requested data or false on failure
// get all areas in which the user is area admin
R.' . $this->alias['right_id'] . ' AS right_id,
'. $this->prefix. $this->alias['area_admin_areas']. ' AAA,
AAA.' . $this->alias['perm_user_id'] . ' = '.
$this->dbc->quote ($perm_user_id);
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
while ($row = $result->fetch (PDO ::FETCH_NUM )) {
$rows[$row[0 ]] = $row[1 ];
* Reads all the group ids in that the user is also a member of
* (all groups that are subgroups of these are also added recursively)
* @param int perm user id
* @return array requested data or false on failure
GU.' . $this->alias['group_id'] . '
GU.' . $this->alias['group_id'] . ' = G. ' . $this->alias['group_id'] . '
GU.' . $this->alias['perm_user_id'] . ' = '.
$this->dbc->quote ($perm_user_id);
G.' . $this->alias['is_active'] . '=' .
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
$col = $result->fetchAll (PDO ::FETCH_COLUMN );
* and put them in the array
* @return array requested data or false on failure
GR.' . $this->alias['right_id'] . ',
MAX(GR.' . $this->alias['right_level'] . ')
GR.' . $this->alias['group_id'] . ' IN('.
GR.' . $this->alias['right_id'] . '';
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
while ($row = $result->fetch (PDO ::FETCH_NUM )) {
$rows[$row[0 ]] = $row[1 ];
* Read the sub groups of the new groups that are not part of the group ids
* @param array new group ids
* @return array requested data or false on failure
DISTINCT SG.' . $this->alias['subgroup_id'] . '
SG.' . $this->alias['subgroup_id'] . ' = G.' .
$this->alias['group_id'] . '
SG.' . $this->alias['group_id'] . ' IN ('.
SG.' . $this->alias['subgroup_id'] . ' NOT IN ('.
G.' . $this->alias['is_active'] . '=' .
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
$col = $result->fetchAll (PDO ::FETCH_COLUMN );
* Read out the rights from the userrights or grouprights table
* that imply other rights along with their level
* @param string name of the table
* @return array requested data or false on failure
TR.' . $this->alias['right_level'] . ',
TR.' . $this->alias['right_id'] . '
TR.' . $this->alias['right_id'] . ' = R.' . $this->alias['right_id'] . '
R.' . $this->alias['right_id'] . ' IN ('.
R.' . $this->alias['has_implied'] . '='.
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
while ($row = $result->fetch (PDO ::FETCH_NUM )) {
$rows[$row[0 ]][] = $row[1 ];
* Read out the implied rights with a given level from the implied_rights table
* @param array current right ids
* @param string current level
* @return array requested data or false on failure
RI.' . $this->alias['implied_right_id'] . ' AS right_id,
'. $currentLevel. ' AS right_level,
R.' . $this->alias['has_implied'] . ' AS has_implied
RI.' . $this->alias['implied_right_id'] . ' = R.' . $this->alias['right_id'] . '
RI.' . $this->alias['right_id'] . ' IN ('.
$result = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'error in query ' . $error_info[2 ] . ' - ' . $query);
$rows = $result->fetchAll (PDO ::FETCH_ASSOC );
* Override the disconnect method from the parent class.
Documentation generated on Mon, 28 Jan 2008 03:30:30 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|