gpt4 book ai didi

php - 无法连接到 MySQL 服务器(2006 错误)

转载 作者:行者123 更新时间:2023-11-29 22:23:34 26 4
gpt4 key购买 nike

所以我最近正在使用 MySQL,但发生了一件非常奇怪的事情..

希望我能在这里找到解决方案!

<?php
$servername = "theServername";
$username = "theUsername";
$password = "thePassword";
$dbname = "theDatabaseName";
$conn = new mysqli($servername,$username,$password,$dbname);

if ($conn->connect_error) {
die("MySQL connection failed: " . $conn->connect_error);
echo "Couldn't connect.";
}
else {
echo "It connected.";
}
?>

它一直向我展示

Warning: mysqli::mysqli(): MySQL server has gone away in C:\Users\Star1\PhpstormProjects\something\database.php on line 10

Warning: mysqli::mysqli(): Error while reading greeting packet. PID=7520 in C:\Users\Star1\PhpstormProjects\something\database.php on line 10

Warning: mysqli::mysqli(): (HY000/2006): MySQL server has gone away in C:\Users\Star1\PhpstormProjects\something\database.php on line 10 MySQL connection failed: MySQL server has gone away

对我来说,第10行是$dbname,它是new mysqli类的最后一个参数。

注意:我将正确的信息放在字符串引号内,但这只是一个示例。

最佳答案

试试这个

$con = mysqli_connect($servername, $username, $password,$dbname);

More Details About- Mysql Server has gone away

关于php - 无法连接到 MySQL 服务器(2006 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30483040/

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