Re: DataObject and Username

From: Date: Wed, 18 Aug 2004 20:10:28 +0000
Subject: Re: DataObject and Username
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-14167@lists.php.net to get a copy of this message
On Wed, 18 Aug 2004 12:56:59 -0500 (EST), Alex Goddard <agoddard@cerias.purdue.edu> wrote: > Hi, > > I'm looking for a way to, if a configuration option is set, connect to a > database using my own username and password instead of the ones given in > the 'database' option of DB_DataObject. That is, I want to use the info > given by a user at login to connect to the database instead of the one > given in the 'database' option. > > I've currently got code that seems to do this some of the time > (immediately after login) by overriding the _connect() method and changing > the DSN if the option is set. However, the changed DSN doesn't seem to > survive after that one use, it gets reset to whatever is in the config > file. > > The idea is to get it so that 'Updated By' will list the correct username > as opposed to the default one given in the DataObject config file. > > Any suggestions as to how this could be done? > I see two options here. 1) Have your users login and store the username in the session, then set the updated by field to this value. 2) If the user is logged in, change the DSN in the config. To do this, you could not use an ini file at all, but set up the config array in-code. You could also just change the DSN before you set the options. $config = parse_ini_file('DataObject.ini', true); $config['DB_DataObject']['database'] = 'mysql://'.$username.':'.$password.'@host/database'; foreach($config as $class => $values) { $options =& PEAR::getStaticProperty($class, 'options'); $options = $values; } -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.pear.general (#14167) next »