我在运行的网站上有下列错误。我不明白为什么,因为它在我的本地主机上正常工作。这与主机有关吗?我在Unix服务器上。MYSQLi错误:用户已经有超过'max_user_connections'活动连接
Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1203): User dbo343879423 already has more than 'max_user_connections' active connections in /homepages/9/d322397966/htdocs/dump/models/class_database.php on line 11
Connect failed: User dbo343879423 already has more than 'max_user_connections' active connections
Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in /homepages/9/d322397966/htdocs/dump/models/class_database.php on line 160
错误说“用户dbo343879423已经有超过‘MAX_USER_CONNECTIONS’在/homepages/9/d322397966/htdocs/dump/models/class_database.php上线11活动连接”,所以这是线11在脚本中 - 我看不到任何错误!
$this -> connection = new mysqli($hostname,$username,$password,$database);
下面是class_database.php整个类,是错误的脚本的另一部分,我应该改变?
<?php
#connects the database and handling the result
class __database {
protected $connection = null;
protected $error = null;
#make a connection
public function __construct($hostname,$username,$password,$database)
{
$this -> connection = new mysqli($hostname,$username,$password,$database);
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
#fetches all result rows as an associative array, a numeric array, or both
public function fetch_all($query)
{
$result = $this -> connection -> query($query);
if($result)
{
return $result -> fetch_all(MYSQLI_ASSOC);
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#fetches a result row as an associative array, a numeric array, or both
public function fetch_assoc_while($query)
{
$result = $this -> connection -> query($query);
if($result)
{
while($row = $result -> fetch_assoc())
{
$return_this[] = $row;
}
if (isset($return_this))
{
return $return_this;
}
else
{
return false;
}
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#fetch a result row as an associative array
public function fetch_assoc($query)
{
$result = $this -> connection -> query($query);
if($result)
{
return $result -> fetch_assoc();
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#get a result row as an enumerated array
public function fetch_row($query)
{
$result = $this -> connection -> query($query);
if($result)
{
return $result -> fetch_row();
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#get the number of rows in a result
public function num_rows($query)
{
$result = $this -> connection -> query($query);
if($result)
{
return $result -> num_rows;
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#performs a query on the database
public function query($query)
{
$result = $this -> connection -> query($query);
if($result)
{
return $result;
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection
public function real_escape_string($string)
{
$result = $this -> connection -> real_escape_string($string);
if($result)
{
return $result;
}
else
{
$this -> error = $this -> connection -> error;
return false;
}
}
#display error
public function get_error()
{
return $this -> error;
}
#closes the database connection when object is destroyed.
public function __destruct()
{
$this -> connection -> close();
}
}
?>
或者我应该只是改变主机的好!
下面是数据库连接类的实现。如果我拿出这部分,错误不会再出现,但我也在网站的其他部分也这样做,并且它们不会造成任何问题!
<!-- side-video-library -->
<div id="side-video-library" class="round-corner">
<h4><a href="<?php echo HTTP_ROOT;?>videos"><span>ENER VIDEO LIBRARY</span></a></h4>
<?php
$sql = "
SELECT *
FROM root_pages
WHERE root_pages.parent_id = '8'
AND root_pages.pg_highlight = '1'
AND root_pages.pg_hide != '1'
ORDER BY rand() DESC
LIMIT 1
";
#instantiate the object of __database class
$object_item = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$item = $object_item -> fetch_assoc($sql);
#instantiate the object of __database class
$object_item_num = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$total_item = $object_item_num -> num_rows($sql);
//echo $total_item;
?>
<?php
if ($total_item > 0)
{
$sql = "
SELECT *
FROM root_tagged
LEFT JOIN root_tags ON (root_tags.tag_id = root_tagged.tag_id)
WHERE root_tagged.pg_id = '".$item['pg_id']."'
";
#instantiate the object of __database class
$object_tagname = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$item_tagname = $object_tagname -> fetch_assoc($sql);
#instantiate the object of __database class
$object_tagname_num = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$total_tagname = $object_tagname_num -> num_rows($sql);
?>
<p class="item-video">
<object style="width: 183px; height: 151px;" width="183" height="151" data="http://www.youtube.com/v/<?php echo get_video_id($item['pg_content_1']) ;?>" type="application/x-shockwave-flash">
<param name="wmode" value="transparent" />
<param name="src" value="http://www.youtube.com/v/<?php echo get_video_id($item['pg_content_1']) ;?>" />
</object>
</p>
<h3><a href="<?php echo HTTP_ROOT.str_replace(' ', '-', 'videos').'/'.$item_tagname['tag_name'].'/'.str_replace(' ', '-', strtolower($item['pg_url']));?>"><?php if(strlen($item['pg_title']) > 20) echo substr($item['pg_title'], 0,20).'...'; else echo $item['pg_title'];?></a></h3>
<p class="item-excerpt-video"><?php if(strlen($item['pg_content_2']) > 100) echo substr($item['pg_content_2'], 0,100).'...'; else echo $item['pg_content_2'];?></p>
<a href="<?php echo HTTP_ROOT;?>videos" class="button-arrow"><span>More</span></a>
<?php
}
?>
</div>
<!-- side-video-library -->
我是不是正在实现类不正确?
谢谢。
您的主机使用哪种版本的PHP?析构函数仅支持PHP5 – 2010-11-02 16:04:39
它是PHP 5 ...谢谢! – laukok 2010-11-02 16:38:25
我对GC的......没有信心......在完成使用类 – 2010-11-02 19:27:53