gpt4 book ai didi

php - 与 MySQL 服务器 'reading initial communication packet' 失去连接,系统错误 : 0 in connecting to Mysql in cpanel

转载 作者:行者123 更新时间:2023-11-30 01:07:15 27 4
gpt4 key购买 nike

我正在使用 cPanel 服务器,但收到此错误。

在“读取初始通信数据包”时失去与 MySQL 服务器的连接,系统错误:0

虽然我读了他的问题Lost connection to MySQL server at 'reading initial communication packet', system error: 0 ,我还是没有得到解决方案。当我运行我的 php 代码时,它返回

“连接成功在‘读取初始通信数据包’时失去与 MySQL 服务器的连接,系统错误:0”

代码如下:

$con = mysql_connect('mysite.com:2082', 'me@mysite.com', 'passwordhere', 'dbname');

if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
echo "Connection successful";
}
if ($selected = mysql_select_db("dbname",$con) or die(mysql_error())){
echo "Your database name is dbname";
}


mysqli_close($con);

感谢您的回答。

最佳答案

我能够解决这个问题。这是代码:

    $con = mysql_connect('localhost', 'serverusername', 'serverpassword');

if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$selected = mysql_select_db("db_name",$con) or die(mysql_error());

关于php - 与 MySQL 服务器 'reading initial communication packet' 失去连接,系统错误 : 0 in connecting to Mysql in cpanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19654311/

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