Re: How to pass connection to next page
| From: | Kevin Stone | Date: | Wed, 23 Jul 2003 19:24:05 +0000 |
| Subject: | Re: How to pass connection to next page | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156506@lists.php.net to get a copy of this message | ||
"Minghua Yao" <yao6889@msmailhub.oulan.ou.edu> wrote in message
news:FC0CEBD77311DA499A67ADB355A24FA20396AD89@mail4.oulan.ou.edu...
>
> > Hi,
> > On one page, I have:
> > <?php
> > .......
> > $dbcnx0 = @mysql_connect("localhost", $name, $password);
> > .......
> > session_start();
> > $_SESSION['my_con'] = $dbcnx0;
> > .......
> > ?>
> > On another page, I have:
> > <?php
> > ..........
> > session_start();
> > $dbcnx1 = $_SESSION['my_con'];
> > .........
> > ?>
> > The problem is:
> > $dbcnx0 = Resource id #1 while $dbcnx1 = 0.
> > The reason I want to pass the handle to next page is that I want to use
> > that connection on the next page to do some queries.
> > Help will be appreciated.
> > -MY
You cannot do what you propose and there is no work around becuase PHP
automatically closes any connctions left open when the script closes,
rendering the resource/object handels invalid.
The compromise most people live with is to put their connection script
within a separate file and include it (either manually or automatically) at
the top of any script they may need to access the database in. This at
least saves you the headache of maintaining twelve different instances of
the same code in a pile of scripts.
- Kevin