MYSQLi错误:用户已经有超过'max_user_connections'活动连接 [英] MYSQLi error: User already has more than 'max_user_connections' active connections

查看:137
本文介绍了MYSQLi错误:用户已经有超过'max_user_connections'活动连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我正在运行的网站上发生以下错误。我不明白为什么在我的本地主机上工作正常。这是与主机有关吗?我在Unix服务器上。

 警告:mysqli :: mysqli()[mysqli.mysqli]:(42000/1203) :用户dbo343879423在/homepages/9/d322397966/htdocs/dump/models/class_database.php第11行已经有超过'max_user_connections'活动连接
连接失败:用户dbo343879423已经有超过'max_user_connections'活动连接
警告:mysqli :: close()[mysqli.close]:无法在第160行的/homepages/9/d322397966/htdocs/dump/models/class_database.php中获取mysqli

错误说'user dbo343879423在/ homeepages中已经有超过'max_user_connections'活动连接/ 9 / d322397966 / htdocs / dump / models /class_database.php在第11行',所以这是脚本中的第11行 - 我看不到任何错误!

  $ this  - > connection = new mysqli($ hostname,$ username,$ password,$ database); 

下面是class_database.php中的整个类,是否在脚本的其他部分出错,我应该更改?

 <?php 
#连接数据库并处理结果
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\\\
,mysqli_connect_error());
exit();
}
}

#将所有结果行作为关联数组,数字数组或两者都获取
public function fetch_all($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
return $ result - > fetch_all(MYSQLI_ASSOC);
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}
}

#获取结果行作为关联数组,数字数组或两者
public function fetch_assoc_while($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
while($ row = $ result - > fetch_assoc())
{
$ return_this [] = $ row;
}

if(isset($ return_this))
{
return $ return_this;
}
else
{
return false;
}
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}
}

#将结果行作为关联数组
public function fetch_assoc($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
return $ result - > FETCH_ASSOC();
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}
}

#将结果行作为枚举数组
public function fetch_row($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
return $ result - > fetch_row();
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}
}

#get结果中的行数
public function num_rows($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
return $ result - > NUM_ROWS;
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}
}

#performs对数据库的查询
public function query($ query)
{
$ result = $ this - >连接 - >查询($查询);
if($ result)
{
return $ result;
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}

}

#escapes在SQL语句中使用的字符串中的特殊字符,考虑到连接的当前字符集
public函数real_escape_string($ string)
{
$ result = $ this - >连接 - > real_escape_string($字符串);
if($ result)
{
return $ result;
}
else
{
$ this - > error = $ this - >连接 - >错误;
返回false;
}

}

#display错误
public function get_error()
{
return $ this - >错误;
}

#当对象被销毁时,#断开数据库连接。
public function __destruct()
{
$ this - >连接 - >关();
}
}
?>

或者我应该只是更改主机好吗?



下面是数据库连接类的实现。如果我把这部分出来,错误不会再出现了,但是我也在网站的其他部分也一样,他们不会造成任何问题!

 <! -  side-video-library  - > 
< div id =side-video-libraryclass =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 __database类的对象
$ object_item = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$ item = $ object_item - > FETCH_ASSOC($的SQL);

#instantiate __database类的对象
$ 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 __database类的对象
$ object_tagname = new __database(DB_HOST,DB_USER,DB_PASS,DB_NAME);
$ item_tagname = $ object_tagname - > FETCH_ASSOC($的SQL);

#instantiate __database类的对象
$ 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 =183height =151data =http://www.youtube.com/v/<?php echo get_video_id($ item ['pg_content_1']);?>类型= 应​​用程序/ x-冲击波闪光 >
< param name =wmodevalue =transparent/>
< param name =srcvalue =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;?> videosclass =button-arrow>< span>更多< / span>< / a>
<?php
}
?>
< / div>
<! - side-video-library - >

我是否正在不正确地执行课程?



谢谢。

解决方案

可能的问题是,你只有少数连接允许,当你的班级试图获得新的连接你有这个错误。



这不是一个编程问题,只是数量的资源可用。而使用这个类的任何其他脚本都有错误。



您必须在服务器上的mysql配置文件上配置更多的连接。如果您没有此访​​问权限,请向支持人员进行更改或更改,以允许更多连接的托管公司进行更改。



其他选项是实施Singleton模式这个类,所以它重复使用相同的连接池,不要爆炸极限。


I have this error below on a site I am running. I don't understand why is that as it works fine on my localhost. Is it something to do with the host? I am on an Unix server.

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

the error says 'User dbo343879423 already has more than 'max_user_connections' active connections in /homepages/9/d322397966/htdocs/dump/models/class_database.php on line 11', so this is the line 11 in the script - I can't see anything wrong!

$this -> connection = new mysqli($hostname,$username,$password,$database);

below is the entire class in class_database.php, is it wrong in other part of script and I should change?

<?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();
    }
}
?>

or should I just change the host for good!??

below is the implementation of the database connection class. If I take this part out, the error won't appear anymore, but I do the same at other parts of the site as well and they won't cause any problem!

<!-- 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 -->

Have I been implementing the class incorrectly??

thanks.

解决方案

Probably the problem is that you have only a handful connections allowed and when your class tries to get a new connection you have this error.

This is not a programming problem, just quantity of resources available. And any other script that uses this class are subject to have the error.

You have to configure more connections on mysql config file on the server. If you don't have this access, ask the support to do it or change for a hosting company with more connections allowed!

Other option is to implement a Singleton pattern on this class, so it reuses same pool of connections, and don't explode the limit.

这篇关于MYSQLi错误:用户已经有超过'max_user_connections'活动连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆