The simplest "way to do the connection thing" is, as is often the case in php,
to do nothing i.e. forget it.

If you don't specify a connect id MySQL happily uses the last one opened, so
the only thing you need do with the return from mysql_connect is check it for
errors i.e.

if (!mysql_connect("localhost","root"))
{
// panic

There's certainly no point in putting it in a session variable, the connection
is closed for you
as your script terminates.

The only time you might want to actually do something is if you were doing a LOT
of
switching between different database servers during one page request.  Switching

between databases doesn't matter, but different servers = different connects.

George





connection if you don't specify one, so the
only thing I've ever done wih

David Johansen wrote:

> I was just wondering what the "right way" to do the MySQL connection thing
> is. Am I supposed to do it everytime through in the php code, should I make
> it a session variable, or is a global variable the way to go? Right now this
> is the code that I have
>
> if (empty($_SESSION['db']))
> {
>    $_SESSION['db'] = mysql_connect("localhost", "root");
>
>    mysql_select_db("clients",$_SESSION['db']);
> }
>
> Is that a "good" way to do it or is there a "better" way or anything like
> that. Thanks,
> Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to