Jump to content

MSQL Connections


johnh2009

Recommended Posts

Hey guys, im so sorry to plant this here, i was hoping to resolve this myself but im having problems with my self employed website.

 

Been a while since i coded any php so ive been cannibalising old code i had from a few years ago, only now im getting this error:

 

http://www.dotcomuk.co.uk/index1.php  -  which is Warning: mysql_connect() [function.mysql-connect]: Too many connections in /home/fhlinux128/d/dotcomuk.co.uk/user/htdocs/_admin/oldb.php on line 6.

 

The file that the info comes from looks as follows:

 

<?php
//function AvaaTietokanta ($osoite = "127.0.0.1",$tietokanta="igpc")
function AvaaTietokanta ($osoite = "******",$tietokanta="*****")
{
//  $yhteysnumero = mysql_connect($osoite,"root","");
  $yhteysnumero = mysql_connect($osoite,"******","*****");
  mysql_select_db($tietokanta);
  
  return $yhteysnumero;

}

// $id -muuttujan tarkistus
// Mikäli $id on jotain muuta kuin numero, niin annetaan virheilmoitus
// ja lopetetaan

function cuttext($text,$num_characters) {
$texto = htmlspecialchars($text);
if (strlen($text) > $num_characters) {
$text = substr($text, 0, $num_characters);
# $text .= " ...";
}
return $text;
}

function convert2proper($strVal){
      $iPos = 0;
      $strValTmp = "";
      do {
                 $iSpace = strpos($strVal," ", $iPos);
                 $strValTmp .= strtoupper(substr($strVal, $iPos, 1));
                 $strValTmp .= strtolower(substr($strVal, $iPos + 1, $iSpace - $iPos));
                 $iPos = $iSpace + 1;
      } while(strpos($strVal," ", $iPos) != FALSE);
      $strValTmp .= strtoupper(substr($strVal, $iPos, 1));
      $strValTmp .= strtolower(substr($strVal, $iPos + 1));
      return $strValTmp;
}
function cutString($strVal,$limit){
      if(strlen($strVal)>$limit){
                 return substr($strVal,0,$limit) . "...";
      }else{
                 return $strVal;
      }
}

?> 

 

Also the code that is grabbing this is as follows:

 

<?php require '_admin/oldb.php';
$yhteys = AvaaTietokanta();?>

<?php
if (!$kysely = mysql_query("select * FROM news order by id desc LIMIT 2",$yhteys))
{
print "<LI>error on loading news!";
}
else
{
while ($row = mysql_fetch_row($kysely)):
$id = $row[0];
$texti = $row[2];
$shownews = cuttext($texti,200);
$added=$row[3]; ?>
<h2><?php echo "$row[1]"; ?></h2>
<h4> » Added on <?php echo gmdate('l jS \of F Y',$added); ?> by <?php echo "$row[4]"; ?></h4>
<p><?php print nl2br($shownews); ?>....<span class="orangeHighlight"><a href="fullnews.php?id=<?php echo "$id"; ?>">Read More</a></span></p><br>
<?php
endwhile;
}
?>
<h3>5 Most Recent News Items</h3>
<?php
$kyselyb = mysql_query("select * FROM news order by id desc LIMIT 5",$yhteys);
while ($row = mysql_fetch_row($kyselyb)):
$idb = $row[0];
$nextheadline = $row[1];
$nextheadline = cuttext($nextheadline,70); ?>

<p>» <a href="fullnews.php?id=<?php echo "$idb"; ?>"><?php echo "$nextheadline"; ?></a></p>

<?php

endwhile;

?>
<br>
<p><a href="news-archive.php">Click Here for All Archived News Items</a></p>



 

TBH im at a loss, ive tried googling but the pages that came up didnt make much sense to me at all.  One site said to log into phpmyadmin and kill processes but when i try to log in i get the too many connections error there too.  I dont know what to do Please help :(

 

The original code was wrote by a Finnish friend of mine many years ago, so sorry about the weird wording on some of the code.

Link to comment
Share on other sites

UPDATE:

 

Ok it seems to have resolved itself....however im pretty sure ive got an eror in my coding for it to have happened in the first place so if anyone has any advice on how to avoid it i would be so grateful. 

 

This site is my livelyhood effectively and i suck majorly at coding, i based my site in tables because i have not got so far as to learn how to layout in css yet:(  It is something ill update but after ive got one going.

 

I am sorry im not a very high contributer but my knowledge is very limited and i fear id cause more issues that resolve right now.

Link to comment
Share on other sites

i see, so is this an issue with my hosts server settings or me not closing mine?

 

If your database is on shared server it might be that the load on the server was too high at this moment. PHP closes all connections automatically when script closes.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.