Re: switching DB's
| From: | Stig S. Bakken | Date: | Mon, 15 Apr 2002 07:39:13 +0000 |
| Subject: | Re: switching DB's | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1140@lists.php.net to get a copy of this message | ||
On Sun, 2002-04-14 at 22:42, Tomas V.V.Cox wrote:
> "Stig S. Bakken" wrote:
> >
> > On Sun, 2002-04-14 at 01:05, destr0 wrote:
> > > I have information in several different databases that I need to access.
> > > With my current database abstraction layer I make use of the
> > > mysql_select_db() function to switch databases on the fly between queries.
> > >
> > > The last time I looked the only way I could change databases with pear was
> > > by opening a second connection with a second dsn. Is there any way with
> > > pear to open a connection once and then switch databases on the same
> > > connection without opening a second connection?
> >
> > We could add a setDatabase method. What do people think? Tomas?
> >
>
> The mysql driver already do what Destr0 say.
>
> $db1 = DB::connect('mysql://root@localhost/db1');
> $dbN = DB::connect('mysql://root@localhost/dbN');
>
> Internally the same connection is used but PEAR DB switchs on the fly
> the database with mysql_select_db().
>
> I don't see the real need for adding setDatabase.
But this is just a side-effect of the mysql connect implementation. If
there is a way to switch database on the same connection in other
databases, relying on a mysql side-effect to give the model for how it
should be done for all of them is really bad. But if it can't be done
in other databases, having setDatabase() won't make sense either.
- Stig