PDA

View Full Version : mysqli_close() when changing databases?


NevadaSam
10-7-07, 09:15 AM
It is neccessary to close and reopen the database connection when changing to a different database?

This is what I am doing:

$connect = mysqli_connect($host,$user,$password);
mysqli_select_db($connect, 'mydb_name_1');

// query, result, etc....
// do stuff with mydb_name_1

mysqli_close($connect);

$connect = mysqli_connect($host,$user,$password);
mysqli_select_db($connect, 'mydb_name_2');

// do stuff with mydb_name_2

mysqli_close($connect);
Could I get by without the mysqli_close() and mysqli_connect() in the middle of this script?

Sam
;

YvetteKuhns
10-7-07, 04:38 PM
It is neccessary to close and reopen the database connection when changing to a different database?

I think so. You should always open and close databases just as you would open and close the bathroom door! You can only have up to ten concurrent connections per database, so you don't want to accidentally keep your connection open and busy when another connection could be required.

If you don't close the first connection, the second set of requests could be performed on the first database.

Croc Hunter
10-8-07, 11:11 AM
Yes I would close too.. neccessary? no. But it is generally best to.