I recently started to set up a site with all my open connection scripts on one page and another page to close the connections. Then I include that file on each individual page. Now .. there's a ton of connections going on there. Is that a bad idea? Should I only have a connection open if I'm using it (I'm guessing it opens all of them at once).
// set on open page
mysql_select_db($database_mainConn, $mainConn);
$query_rsAbout = "SELECT * FROM content WHERE cid = 2";
$rsAbout = mysql_query($query_rsAbout, $mainConn) or die(mysql_error());
$row_rsAbout = mysql_fetch_assoc($rsAbout);
$totalRows_rsAbout = mysql_num_rows($rsAbout);
// set on close page
mysql_free_result($rsAbout);
If I shouldn't do it that way, would it be okay to set them up so that it only opens a connection if it's on a specific page? That way I could still keep everything centralized on one page to edit easier if I need to.
// set on open page
if($_SERVER['REQUEST_URI']=="/thispage/" || $_SERVER['REQUEST_URI']=="/thispage/index.php") {
mysql_select_db($database_mainConn, $mainConn);
$query_rsAbout = "SELECT * FROM content WHERE cid = 2";
$rsAbout = mysql_query($query_rsAbout, $mainConn) or die(mysql_error());
$row_rsAbout = mysql_fetch_assoc($rsAbout);
$totalRows_rsAbout = mysql_num_rows($rsAbout);
}
// set on close page
if($_SERVER['REQUEST_URI']=="/thispage/" || $_SERVER['REQUEST_URI']=="/thispage/index.php") {
mysql_free_result($rsAbout);
}
Thanks.