Re: General Mysql Connect
| From: | Waynn Lue | Date: | Wed, 29 Oct 2008 22:09:29 +0000 |
| Subject: | Re: General Mysql Connect | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282588@lists.php.net to get a copy of this message | ||
Yeah, it's the same user, same everything (for now). But I wonder why
we're seeing these "lost connection" errors and I'm trying to fix
it--this was one of the things I was investigating.
On 10/29/08, Chris <dmagick@gmail.com> wrote:
> Waynn Lue wrote:
>> I sent an email to the mysql list, but it reminded me of a question I had
>> for people structuring their PHP code. What's the general way that people
>> structure their connections? Right now, I spawn off two mysql_connect
>> calls
>> at the top of the file that includes my database calls, using "true" for
>> the
>> fourth parameters, so as to create two new connections. Then I use those
>> two connections for two different databases I have to query from.
>>
>> Is it better just to use mysql_select_db within the query function every
>> time for the same connection? Should I use mysql_connect every time
>> without
>> using "true", so as to re-use connections. Should I be using pconnect
>> instead?
>>
>> I spent some time looking for answers to these questions, but am getting
>> conflicting answers. Some people think relying on the re-use of these
>> functions is good, some think that explicit management is better. In
>> general, how have people on the list found them? For example, is having
>> constant mysql_select_db calls a problem?
>
> Are they connecting as the same user and on the same server? Then you
> can replace with a mysql_select_db call.
>
> If they aren't both of those, you have no choice.
>
> No idea if it'll make much of a difference (performance wise etc) but
> I'd leave it as two connections.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>