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 Code:<?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.
But i'm getting several errors on my site saying I have Too many connectionsPHP Code:<?php
include ('initial_connect.php');
// Connect to news database
news_connect();
//Rest of code
Is there anything I can do, or change in my code to fix this, or make it work more efficiently?
Thanks
Chris







Bookmarks