gpt4 book ai didi

php - PDO 和 MySQL 'max_user_connections'

转载 作者:行者123 更新时间:2023-11-29 06:34:45 25 4
gpt4 key购买 nike

我有一个适用于 Android、Windows Phone 和 iOS 应用程序的 PHP REST API。 API 的响应始终是 JSON。我们使用 DataBase 类来管理 PDO 连接和 CRUD 操作。有时我们会遇到以下错误 Message: SQLSTATE[42000] [1203] User my_user already has more than 'max_user_connections' active connections

我发现一些指令建议将 PDO 对象变量设置为 null,例如 $pdo = nullunset($pdo)。因此,我在我的 DataBase 类中创建了一个析构函数方法来取消设置我的 PDO 实例:

public function __destruct(){
$this->pdo = null;
unset($this->pdo);
}

但有时我又报错了。有人可以帮助我吗?

最佳答案

您使用什么作为连接背景?你使用连接池吗?

看PHP文档主题“Connections and Connection management

Note:

If you're using the PDO ODBC driver and your ODBC libraries support ODBC Connection Pooling (unixODBC and Windows are two that do; there may be more), then it's recommended that you don't use persistent PDO connections, and instead leave the connection caching to the ODBC Connection Pooling layer. The ODBC Connection Pool is shared with other modules in the process; if PDO is told to cache the connection, then that connection would never be returned to the ODBC connection pool, resulting in additional connections being created to service those other modules.

希望这会有所帮助。

关于php - PDO 和 MySQL 'max_user_connections',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25623688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com