stfc_boy
05-07-2009, 05:26 PM
Hello All,
I'm looking for some advice with my connection script to my database.
In my content management system I have a page (initial_connect.php) that is included on all my pages in my content management system.
It contains two connections to different mysql databases via functions (but those databases sit on the same server but I can't have them together in one DB). One to get the initial data from a function called initial_connect and one to get all my news items called news_connect
<?php
/*****************************************************************
- INITIAL CONNECTION
******************************************************************/
function initial_connect() {
$result = mysql_connect("localhost", "usernamehere", "passwordhere");
if (!$result) { return FALSE; }
if (!mysql_select_db("1STdatabasename")) { return FALSE; }
return $result;
}
/*****************************************************************
- GET INDIVIDUAL SITE DETAILS FROM connections TABLE
******************************************************************/
initial_connect();
$SQL = "SELECT * FROM connection_details'";
$result = mysql_query($SQL) or die (mysql_error());
$siteDetails = mysql_fetch_array($result);
$sitename = $siteDetails['name'];
$googleCode = $siteDetails['google'];
//etc
/*****************************************************************
- CONNECT TO THE NEWS DATABASE
******************************************************************/
function news_connect() {
$result = mysql_connect("localhost", "usernamehere", "passwordhere");
if (!$result) { return FALSE; }
if (!mysql_select_db("2NDdatabasename")) { return FALSE; }
return $result;
}
?>
Now, thoughout all my pages in my content management system I include initial_connect.php like so, and also open the connection to the news_connect() function and have about 25 pages in my CMS.
<?php
include ('initial_connect.php');
// Connect to news database
news_connect();
//Rest of code
But i'm getting several errors on my site saying I have Too many connections
Is there anything I can do, or change in my code to fix this, or make it work more efficiently
Thanks
Chris
I'm looking for some advice with my connection script to my database.
In my content management system I have a page (initial_connect.php) that is included on all my pages in my content management system.
It contains two connections to different mysql databases via functions (but those databases sit on the same server but I can't have them together in one DB). One to get the initial data from a function called initial_connect and one to get all my news items called news_connect
<?php
/*****************************************************************
- INITIAL CONNECTION
******************************************************************/
function initial_connect() {
$result = mysql_connect("localhost", "usernamehere", "passwordhere");
if (!$result) { return FALSE; }
if (!mysql_select_db("1STdatabasename")) { return FALSE; }
return $result;
}
/*****************************************************************
- GET INDIVIDUAL SITE DETAILS FROM connections TABLE
******************************************************************/
initial_connect();
$SQL = "SELECT * FROM connection_details'";
$result = mysql_query($SQL) or die (mysql_error());
$siteDetails = mysql_fetch_array($result);
$sitename = $siteDetails['name'];
$googleCode = $siteDetails['google'];
//etc
/*****************************************************************
- CONNECT TO THE NEWS DATABASE
******************************************************************/
function news_connect() {
$result = mysql_connect("localhost", "usernamehere", "passwordhere");
if (!$result) { return FALSE; }
if (!mysql_select_db("2NDdatabasename")) { return FALSE; }
return $result;
}
?>
Now, thoughout all my pages in my content management system I include initial_connect.php like so, and also open the connection to the news_connect() function and have about 25 pages in my CMS.
<?php
include ('initial_connect.php');
// Connect to news database
news_connect();
//Rest of code
But i'm getting several errors on my site saying I have Too many connections
Is there anything I can do, or change in my code to fix this, or make it work more efficiently
Thanks
Chris