开发者社区> 问答> 正文

PHP Mysqli数据库连接池,以避免最大用户数

I surfed on Internet for past two days to create the DB pooling by PHP, but not yet achieved. I'm using PHP and MySQLi. We bought the mysqli db with 15 Maximum user connection. I want to pool the db connection to avoid the new connection. I used

persistent

as well as

mysqli_connect

. but I don't feel much different both are creating the new connection since other user already logged in. I was trying this function to get

connection.

 <?php
function getConnection(){
    if ($connect){
        return $connect;
    }else{
        $connect = new mysqli('p:xxxx','yyy','zzz','aaaa');
        return $connect;
        if(mysqli_connect_errno($connect))
        {
            echo "Server Busy";
        }
    }
}
 ?>

But above function only returns the else part. Please suggest me how to handle this. Thanks in advance. For now I'm killing the process which are in sleep mode to reduce the probability of increasing DB connection.

遇到了同样的问题,在CSDN看到了,希望阿里云团队能够给出正确、标准的答案~请查看

展开
收起
刘刚_ 2020-05-23 21:07:12 784 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
DTCC 2022大会集锦《云原生一站式数据库技术与实践》 立即下载
阿里云瑶池数据库精要2022版 立即下载
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载