php - 打开与 mysql 数据库的多个连接的脚本

标签 php mysql linux

我正在cloudlinux环境上评估MySQL Governor(还安装了CentOS和Cpanel) 这是一个测试服务器,因此没有运行实际的数据库连接。

我希望能够限制数据库用户连接的数量。

我在 MySQL 调控器中设置了限制,但无法测试它。我需要某种脚本(php?)来打开一堆 MySQL 连接才能看到一些结果。

这是我尝试运行的示例代码,它应该生成多个连接,但它只打开一个。

<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "db";

// Create connection

while(1) {
#$conn = new mysqli($servername, $username, $password, $dbname);
$conn = mysql_pconnect($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
}

?>

谢谢

最佳答案

也许是这样的?一个简单的循环,很可能我可能没有很好地理解你的问题。您可以使用简单的简单循环进行多次连接。

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$i = 0;
while($i<4) { //here loop untill 4..
$i++;
echo $i; //just to echo the number... 
$conn = new mysqli($servername, $username, $password, $dbname);
//$conn = mysql_pconnect($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else{
    echo 'Success';
    }
}

?>

关于php - 打开与 mysql 数据库的多个连接的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27781661/

相关文章:

php - 不插入数据库。 PHP 和 MySQL

linux - 在 linux 中使文件对 magento 可写

linux - Linux-Unix 中的中文/日文用户名

php - 操作数应包含 1 列,但在子查询中需要一个最大值(值)

php - 删除php数组列表中的重复值

mysql - 如何在多表搜索中找到我的结果表?

mysql - 检测高于阈值的近似重复项

linux - 打印目录中超过 54 个字的文件名

php - 安装Xdebug后phpinfo中的OLDPWD是什么?

javascript - 电子表格中的链接未显示在 Google html 服务页面中