Re: Re: DB: Changing database during script execution

From: Date: Mon, 22 Jul 2002 12:42:06 +0000
Subject: Re: Re: DB: Changing database during script execution
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7844@lists.php.net to get a copy of this message
On Mon, 22 Jul 2002 14:35:12 +0200, Tomas V.V.Cox wrote: >Martin Jansen wrote: >> >> On Mon, 22 Jul 2002 10:46:38 +0200, Martin Jansen wrote: >> >> >What is the recommened way to change the database while executing a >> >script using PEAR DB? >> >> For the notes: I already tried $dbh->_db = 'new_db' and that's working >> of course, but IMO this is no elegant solution at all. >> > >What about: > >$db->disconnect(); >$db = DB::connect($new_dsn); I don't want to pass a new DSN, I just want to (temporarily) use another database. Thus disconncting and opening a new connection is not necessary. What about function pushDatabase($db = '') { array_push($this->_db_stack, $this->_db); $this->_db = $db; } function popDatabase() { $this->_db = array_pop($this->_db_stack); } (Above code is not tested and surely not very well thought, but it should give you the idea.) With this functions one has the chance to switch between different databases during execution time just like he can switch between error modes via PEAR::pushErrorHandler() and PEAR::popErrorHandler(). Do you think this makes sense and can be applied to all other database systems than MySQL? - Martin

« previous php.pear.dev (#7844) next »