0

Hello,

In my code I am getting this error:

Warning: mysql_connect() [function.mysql-connect]: User turt2liv_demo already has more than 'max_user_connections' active connections in /home/turt2liv/public_html/demo/jamond_website/class.php on line 11

That method looks like this:

//Constructor
	function __construct($debug){
		if(!$debug){
			$debug=0;
		}
		mysql_connect("localhost","turt2liv_demo","demoacc") or die("Connection Error: ".mysql_error()); 
		mysql_select_db("turt2liv_demo_jamond_website") or die("Selection Error: ".mysql_error());
		error_reporting($debug);
		date_default_timezone_set("America/Edmonton");
		if($this->isLoggedIn()){
			setcookie("username",$_COOKIE['username'],time()+3600,"/");
		}
	}

and it only happens on the page that uses this code:

//Catalogue
	public function catalogue($start,$search,$sort,$order){
		if(!$start){
			$start = 0;
		}
		$q = mysql_query("SELECT * FROM `items` WHERE `verified`='1'")or die(mysql_error());
		$num = mysql_num_rows($q) or die(mysql_error());
		echo "<p>Songs are priced based on the Admin's choice, keep in mind though, VIP Accounts can download right away for $10.00 a month. You are not aloud to download or buy without an account! Our sample audio player is brough to you by <a href='http://www.premiumbeat.com/flash_media_players/'>Premium Beat</a>.</p>";
		echo "<p>To save music, right click the \"Download Now\" link and select \"Save Target As\" (or the equivlent of). This method does not work on \"Buy Now\" buttons. If you would like more information on a song, simply click it's name.</p>";
		echo "<div style='background:#151515;width:700px;'>".$this->getSortOptions($search,$start)."</div>";
		echo "<table border=0 style='width:700px;'>";
		$searchDo = false;
		if(isset($search)){
			$search = " AND (name LIKE '%".$search."%' OR owner LIKE '%".$search."%') ";
			$searchDo = true;
		}else{ 
			$search = " ";
		}
		if(isset($sort)){
			if($sort == "mostrecent"){
				$q = mysql_query("SELECT * FROM items WHERE verified='1'".$search."ORDER BY date $order LIMIT $start, 20")or die("ERROR 1: ".mysql_error());
			}else if($sort == "topdownloaded"){
				$q = mysql_query("SELECT * FROM items WHERE verified='1'".$search."ORDER BY hits $order LIMIT $start, 20")or die("ERROR 2: ".mysql_error());
			}else if($sort == "artist"){
				$q = mysql_query("SELECT * FROM items WHERE verified='1'".$search."ORDER BY owner $order LIMIT $start, 20")or die("ERROR 3: ".mysql_error());
			}else if($sort == "song"){
				$q = mysql_query("SELECT * FROM items WHERE verified='1'".$search."ORDER BY name $order LIMIT $start, 20")or die("ERROR 4: ".mysql_error());
			}
		}else{
			$q = mysql_query("SELECT * FROM items WHERE verified='1'".$search."LIMIT ".$start.", 20;")or die("ERROR 5: ".mysql_error()."<br>"."SELECT * FROM items WHERE verified='1'".$search."LIMIT ".$start.", 20;");
		}
		if($searchDo){
			$res = mysql_num_rows($q);
			echo "<tr><td colspan=5 style='border-bottom:1px #6E6E6E solid;'><center><p>$res Results Found.</p></center></td></tr>";
		}
		echo "<tr><th style='border-bottom:1px #6E6E6E solid;'>Sample</th><th style='border-bottom:1px #6E6E6E solid;width:225px;'>Song Name</th><th style='border-bottom:1px #6E6E6E solid;width:125px;'></th><th style='border-bottom:1px #6E6E6E solid;width:225px;'>Artist</th><th style='border-bottom:1px #6E6E6E solid;width:125px;'>Buy Now</th></tr>";
		if(mysql_num_rows($q) >= 1){
			while($a = mysql_fetch_array($q)){
				$id = $a['id'];
				$name = $a['name'];
				$artist = $a['owner'];
				$sample = $a['samplePath'];
				$path = $a['actualPath'];
				$id = $a['id'];
				if($this->isLoggedIn()){
					if($this->isVIP()||$this->isServiceRep()){
						$butt = "<a href='$path'>Download Now</a>";
					}else{
						$q2 = mysql_query("SELECT * FROM boughtItems WHERE email='$email' AND item='$id'");
						if($a['owner_email']==$_COOKIE['username'] || mysql_num_rows($q2) == 1){
							$butt = "<a href='$path'>Download Now</a>";
						}else{
							$butt = $this->purchaseButton($name,$a['cost']);
						}
					}
				}else{
					$butt = "Please Login First!";
				}
				echo "<tr><td style='border-bottom:1px #6E6E6E solid;'>".$this->audioPlayer($sample)."</td><td style='border-bottom:1px #6E6E6E solid;width:225px;'><a href='viewSong.php?id=$id'>$name</a></td><td style='border-bottom:1px #6E6E6E dashed;width:125px;'></td><td style='border-bottom:1px #6E6E6E solid;width:225px;'>$artist</td><td style='border-bottom:1px #6E6E6E solid;width:125px;'>$butt</td></tr>";
			}
		}else{
			echo "<tr><td colspan=5 style='border-bottom:1px #6E6E6E solid;'><center><p>No Results! Sorry.</p></center></td></tr>";
		}
		echo "<tr><td colspan=5 style='border-bottom:1px #6E6E6E solid;'><center><p>".$this->getPages("cat.php",$start, $num)."</p></center></td></tr>";
		echo "</table>";
	}

Any help would be appreciated :)

EDIT:

Easier to read code here

Edited by turt2live: Too much code formating (too long)

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by turt2live
0

I get a broken link for the source code.

If you already have a connection established to the database, your class doesn't need to create another one when using the mysql_* functions. The connection, once made exists in any scope like a superglobal.

0

Link Fixed. Sorry about that.

The script uses OOP to handle everything, the __construct starts the connection and mysql_connect/select_db is never called again in the code.

0

Sorry about that... Website transfer and all that.

Turns out that the error it was giving me was wrong, instead I had an infinite loop in one of the functions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.