Re: Auth, patch to use existing DB object
| From: | Yavor Shahpasov | Date: | Mon, 08 Sep 2003 12:03:24 +0000 |
| Subject: | Re: Auth, patch to use existing DB object | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-21176@lists.php.net to get a copy of this message | ||
Hi tias,
I saw that this is implemented in Auth
here is an example
$params = array('dsn'=>&$db, 'table'=>'users', 'db_fields'=>'*');
$auth_obj = new Auth('DB', $params, 'login', true);
where $db is a connected instance of DB.
Regards
Yavor
Yavor Shahpasov wrote:
Hello the patch looks ok, as far as I know this has not been implemened in CVS. I'll have a look at this and possible commit it tomorrow along with the other patch I glimpsed in the mail list. Yavor Tias wrote:Hello, about the Auth package, stable version 1.2.2 (dont know how to access cvs so maybe its allready done by somebody else) i saw that it was possible to pass an existing container, but not possible to pass an existing DB object... this little patch allows you to pass an existing DB object, so that the (freshly made) container uses it (in stead of having to give a dsn and create a new DB object) It does this through the 'options' paramter (mixed) of Auth::Auth (whithout changing its code) An example on how to use this would be: require_once('DB.php'); $dsn = "mysql://foo:bar@example.org/auth" $db = DB::connect($dsn); unset($dsn); //other stuff require_once("Auth/Auth.php"); $auOpt = array("DB" => &$db, "table" => "users", "usernamecol" => "nick", "passwordcol" => "pass", );$au = new Auth("DB", $auOpt, "", true); the options keyword here is 'DB' but that can be easely changed this is the patch, Container/DB.php --- DB_orig.php 2003-08-23 21:54:23.000000000 +0200+++ DB.php 2003-08-23 21:56:47.000000000 +0200@@ -191,7 +191,9 @@function _parseOptions($array) { foreach ($array as $key => $value) { - if (isset($this->options[$key])) { + if (($key == "DB") && (is_object($value)) && (DB::isConnection($value)) { + $this->db = $value; + } elseif (isset($this->options[$key])) { $this->options[$key] = $value; } }