Auth DB container prolems
| From: | Yavor Shahpasov | Date: | Mon, 17 Mar 2003 11:55:31 +0000 |
| Subject: | Auth DB container prolems | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-14356@lists.php.net to get a copy of this message | ||
Find attahched a patch which deals with some error handing in the DB
container.
a) in set defaults the dsn is set to null and not to an empty string, if set
to an empty sting it would not be caught in the error whanding in the
Auth_Container_DB which checks for is empty _after the _setDefaults is
called
from Auth_Container_DB
$this->_setDefaults();
if (is_array($dsn)) {
$this->_parseOptions($dsn);
if (empty($this->options['dsn'])) {
PEAR::raiseError("No connection parameters specified!");
}
} else {
$this->options['dsn'] = $dsn;
}
b) Error checks should be done with
if (DB::isError($res) || PEAR::isError($res)) {
instead of
if (DB::isError($res)) {
this will catch errors triggered by PEAR:Auth::DB it'self which uses
PEAR::raiseError to trigger errors, alternativelly you could use
DB::raiseError (dunno if this is valid ) to triger errors
Regards Yavor
--- DB.php Mon Mar 17 13:50:29 2003 +++ DB.php.orig Mon Mar 17 13:48:53 2003 @@ -107,7 +107,7 @@ } - if (DB::isError($this->db) || PEAR::isError($this->db)) { + if (DB::isError($this->db)) { return PEAR::raiseError("", $this->db->code, PEAR_ERROR_DIE); } else { return true; @@ -131,10 +131,7 @@ function query($query) { if (!DB::isConnection($this->db)) { - $res = $this->_connect($this->options['dsn']); - if(DB::isError($res) || PEAR::isError($res)){ - return($res); - } + $this->_connect($this->options['dsn']); } return $this->db->query($query); } @@ -152,7 +149,7 @@ $this->options['table'] = "auth"; $this->options['usernamecol'] = "username"; $this->options['passwordcol'] = "password"; - $this->options['dsn'] = null; + $this->options['dsn'] = ""; $this->options['db_fields'] = "*"; $this->options['cryptType'] = "md5"; } @@ -212,8 +209,8 @@ $res = $this->query($query); - if (DB::isError($res) || PEAR::isError($res)) { - return PEAR::raiseError($res->getMessage(), $res->code, PEAR_ERROR_DIE); + if (DB::isError($res)) { + return PEAR::raiseError("", $res->code, PEAR_ERROR_DIE); } else { $entry = $res->fetchRow(DB_FETCHMODE_ASSOC);
--- DB.php Mon Mar 17 13:50:29 2003 +++ DB.php.orig Mon Mar 17 13:48:53 2003 @@ -107,7 +107,7 @@ } - if (DB::isError($this->db) || PEAR::isError($this->db)) { + if (DB::isError($this->db)) { return PEAR::raiseError("", $this->db->code, PEAR_ERROR_DIE); } else { return true; @@ -131,10 +131,7 @@ function query($query) { if (!DB::isConnection($this->db)) { - $res = $this->_connect($this->options['dsn']); - if(DB::isError($res) || PEAR::isError($res)){ - return($res); - } + $this->_connect($this->options['dsn']); } return $this->db->query($query); } @@ -152,7 +149,7 @@ $this->options['table'] = "auth"; $this->options['usernamecol'] = "username"; $this->options['passwordcol'] = "password"; - $this->options['dsn'] = null; + $this->options['dsn'] = ""; $this->options['db_fields'] = "*"; $this->options['cryptType'] = "md5"; } @@ -212,8 +209,8 @@ $res = $this->query($query); - if (DB::isError($res) || PEAR::isError($res)) { - return PEAR::raiseError($res->getMessage(), $res->code, PEAR_ERROR_DIE); + if (DB::isError($res)) { + return PEAR::raiseError("", $res->code, PEAR_ERROR_DIE); } else { $entry = $res->fetchRow(DB_FETCHMODE_ASSOC);