RE: [PHP] Database Handles
| From: | Samantha Savvakis | Date: | Wed, 06 Dec 2000 04:44:35 +0000 |
| Subject: | RE: [PHP] Database Handles | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28844@lists.php.net to get a copy of this message | ||
I always pass on the optional argument to specify the database connection.
This is why it is very strange. I always write: mysql_query($sqlquery,
$dbhandle) etc. for all my mysql functions.
I am using the optional argument and it seems that it's always taking the
last opened database despite of the extra argument.
I'm going to do a little more investigation into the persistent connection
issue.
> -----Original Message-----
> From: Richard Lynch [mailto:richard@zend.com]
> Sent: Wednesday, 6 December 2000 13:58
> To: php-general@lists.php.net
> Subject: Re: [PHP] Database Handles
>
>
> All the mysql_xxx() functions take an optional argument to specify which
> database connection you are trying to use.
>
> If you are not using that argument, they use the last-opened
> database... In
> theory, at least.
>
> Be very careful that all your included files and functions specify which
> connection they are using, or do not cache the first connection
> and then use
> that.
>
> It's certainly possible to use two connections, not only one after the
> other, but concurrently, if you keep it all straight.
>
> However, with persistent connections, you may need to be extra
> careful... I
> don't *think* you'll get back the same connection if you ask for one when
> there is already one open... But I've never actually tried it.
>
> Try using just mysql_connect if you really think pconnect is
> messing you up.
>
> ----- Original Message -----
> From: "Samantha Savvakis" <samantha@cfs.net.au>
> Newsgroups: php.general
> Sent: Tuesday, December 05, 2000 7:43 PM
> Subject: [PHP] Database Handles
>
>
> > Hi,
> >
> > I have a situation where I need to connect to two different databases.
> >
> > I find that if I open the handle to database ABC, then open handle to
> > database XYZ, when it goes to call FunctionB, it thinks it's
> using handle
> 1
> > for database ABC but I get the error that it can't find the table
> > XYZ.TABLENAME - it should be looking for ABC.TABLENAME;
> >
> > Here is the pseudocode:
> >
> > <?
> > require("dbfunctions.inc"); // db wrapper functions
> >
> > // main routine
> > $db = db_connection("ABC"); // Database ABC
> >
> > $code = FunctionA();
> > // Inside function A, it creates a second DB handle to Database XYZ
> >
> > $price = FunctionB($code, $db);
> > // Inside function B, it uses the first DB handle for database ABC
> >
> > // I do more with $db to database ABC, hence I leave it open
> >
> > FunctionA()
> > {
> > $db2 = db_connection("XYZ"); // Database XYZ
> > ....
> > do some querying
> > ...
> > db_close($db2); // Close handle to the second database
> > }
> >
> > FunctionB($code, $db)
> > {
> > ....
> > do some querying
> > ....
> > }
> > ?>
> >
> > Theoretically this should work.
> >
> > I find that if I go into FunctionA first, without creating the first
> handle
> > to database ABC, and then after FunctionA create the first
> handle to ABC,
> it
> > works.
> >
> > I am using persistant connections mysql_pconnect(); - maybe that's got
> > something to do with it.
> >
> > I'm using version 4.0.2 of PHP
> >
> > Sam
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>