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
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
switching between different database servers during one page request. Switching
between databases doesn't matter, but different servers = different connects.
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");
> Is that a "good" way to do it or is there a "better" way or anything like
> that. Thanks,
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php