Jump to content

Recommended Posts

Posted

Hey!

So my Heliohost site is up and running smoothly, but not optimally. As visits increase, I've been getting errors regarding exceeding the number of allowed MySQL connections.So I looked up a snippet and adapted it to my needs. Question is, since I can't really see the amount of current MySQL connections in a way that I'm aware of, would this snippet theoretically do the job?Did I adapt it correctly? I include this wherever I need a db connection(Most every page) and call GetMyConnection().

 

(fatal_error() just dies with an image attached)

<?php
   if (!isset($g_link)) {
       $g_link = false;
   }

   function GetMyConnection()
   {
       global $g_link;
       if( $g_link )
           return $g_link;
       $g_link = @mysql_pconnect( 'localhost:3306', 'usr', 'pwd') or fatal_error("Could not connect to mysql server.<!--".mysql_error()."-->" );
       @mysql_select_db('db', $g_link) or fatal_error("Could not select database.<!--".mysql_error()."-->");
       return $g_link;
   }

?>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...