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.23 2006/08/15 06:43:20 mahono Exp $
* @link http://pear.php.net/LiveUser
* Require parent class definition
require_once 'LiveUser/Auth/Common.php';
* PDO container for Authentication. This is a PHP5 only driver.
* This is a PDO backend driver for the LiveUser class.
* - 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
* dsn that was connected to
* Database connection object.
* Database connection options.
* Prefix for all db tables the container has.
* determines of the use of sequences should be forced
* Load the storage container
* @param array array containing the configuration.
* @param string name of the container that should be used
* @return bool true on success or false on failure
function init(&$conf, $containerName)
parent ::init($conf, $containerName);
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'));
* Writes current values for the user back to the database.
* @return bool true on success or false on failure
function _updateUserData ()
$query = 'UPDATE ' . $this->prefix . $this->alias['users']. '
SET ' . $this->alias['lastlogin']
WHERE ' . $this->alias['auth_user_id']
$rows_affected = $this->dbc->exec ($query);
if ($rows_affected === false ) {
$error_info = $this->dbc->errorInfo ();
'reason' => $error_info[2 ],
* Reads user data from the given data source
* If only $handle is given, it will read the data
* from the first user with that handle and return
* If $handle and $passwd are given, it will try to
* find the first user with both handle and password
* matching and return true on success (this allows
* multiple users having the same handle but different
* passwords - yep, some people want this).
* if only an auth_user_id is passed it will try to read the data based on the id
* If no match is found, false is being returned.
* @param string user handle
* @param string user password
* @param bool|intif the user data should be read using the auth user id
* @return bool true on success or false on failure
function readUserData($handle = '', $passwd = '', $auth_user_id = false )
foreach ($this->tables['users']['fields'] as $field => $req) {
$fields[] = $this->alias[$field] . ' AS ' . $field;
// Setting the default query.
$query = 'SELECT ' . implode(',', $fields) . '
$query .= $this->alias['auth_user_id'] . '='
. $this->dbc->quote ($auth_user_id);
array ('reason' => 'No handle set in storage config.')
foreach ($this->handles as $field) {
$handles[] = $this->alias[$field] . '=' .
$this->dbc->quote ($handle);
$query .= '(' . implode(' OR ', $handles) . ')';
// If $passwd is set, try to find the first user with the given
$query .= ' AND ' . $this->alias['passwd'] . '='
. $this->dbc->quote ($this->encryptPW($passwd));
$res = $this->dbc->query ($query);
$error_info = $this->dbc->errorInfo ();
'reason' => $error_info[2 ],
$result = $res->fetch (PDO ::FETCH_ASSOC );
if ($result === false && $this->dbc->errorCode () != '00000') {
'reason' => $this->dbc->errorCode (),
'debug' => $this->dbc->errorInfo ()
// User was found, read data into class variables and set return value to true
$result['lastlogin'] = strtotime($result['lastlogin']);
* properly disconnect from database
* @return bool true on success or false on failure
Documentation generated on Mon, 28 Jan 2008 03:30:29 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|