cvs: pear /Auth/Container DB.php

From: Date: Mon, 28 Jul 2003 21:56:55 +0000
Subject: cvs: pear /Auth/Container DB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-11791@lists.php.net to get a copy of this message
yavo Mon Jul 28 17:56:55 2003 EDT Modified files: /pear/Auth/Container DB.php Log: Fix a parse error Add a fix for db_fields = * Index: pear/Auth/Container/DB.php diff -u pear/Auth/Container/DB.php:1.35 pear/Auth/Container/DB.php:1.36 --- pear/Auth/Container/DB.php:1.35 Sun Jul 20 16:08:18 2003 +++ pear/Auth/Container/DB.php Mon Jul 28 17:56:55 2003 @@ -16,7 +16,7 @@ // | Authors: Martin Jansen <mj@php.net> | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.35 2003/07/20 20:08:18 quipo Exp $ +// $Id: DB.php,v 1.36 2003/07/28 21:56:55 yavo Exp $ // require_once 'Auth/Container.php'; @@ -30,7 +30,7 @@ * * @author Martin Jansen <mj@php.net> * @package Auth - * @version $Revision: 1.35 $ + * @version $Revision: 1.36 $ */ class Auth_Container_DB extends Auth_Container { @@ -174,7 +174,7 @@ $this->options['table'] = 'auth'; $this->options['usernamecol'] = 'username'; $this->options['passwordcol'] = 'password'; - $this->options['dsn'] = '; + $this->options['dsn'] = ''; $this->options['db_fields'] = ''; $this->options['cryptType'] = 'md5'; } @@ -195,6 +195,13 @@ $this->options[$key] = $value; } } + + /* Include additional fields if they exist */ + if(!empty($this->options['db_fields'])){ + if(is_array($this->options['db_fields'])){ + $this->options['db_fields'] = join($this->options['db_fields'], ', '); + } + } } // }}} @@ -221,21 +228,22 @@ return PEAR::raiseError($err->getMessage(), $err->getCode()); } - // Include additional fields if they exist - $cols = ''; - if (!empty($this->options['db_fields'])) { - $cols = ',' . $this->options['db_fields']; + // Find if db_fileds contains a *, i so assume all col are selected + if(strstr($this->options['db_fields'], '*')){ + $sql_from = "*"; + } + else{ + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].", ".$this->options['db_fields']; } - $query = sprintf("SELECT %s FROM %s WHERE %s = '%s'", - $this->options['usernamecol'] . ', ' - . $this->options['passwordcol'] - . $cols, + $query = "SELECT ! FROM ! WHERE ! = ?"; + $query_params = array( + $sql_from, $this->options['table'], $this->options['usernamecol'], $username ); - $res = $this->db->getRow($query, null, DB_FETCHMODE_ASSOC); + $res = $this->db->getRow($query, $query_params, DB_FETCHMODE_ASSOC); if (DB::isError($res)) { return PEAR::raiseError($res->getMessage(), $res->getCode()); @@ -275,8 +283,16 @@ $retVal = array(); + // Find if db_fileds contains a *, i so assume all col are selected + if(strstr($this->options['db_fields'], '*')){ + $sql_from = "*"; + } + else{ + $sql_from = $this->options['usernamecol'] . ", ".$this->options['passwordcol'].", ".$this->options['db_fields']; + } + $query = sprintf("SELECT %s FROM %s", - (empty($this->options['db_fields']) ? '*' : $this->options['db_fields']), + $sql_from, $this->options['table'] ); $res = $this->db->getAll($query, null, DB_FETCHMODE_ASSOC);

« previous php.pear.cvs (#11791) next »