这是我连接数据库的代码:
$datbase=mysqli_connect("localhost:82","root"," ");
if(!$datbase)
{
die("connection failed".mysqli_connect_error());
}
它告诉我
Warning: mysqli_connect(): MySQL server has gone away in C:\Program Files\apache24\Apache24\htdocs\PhpProject3\php_DataBase.php on line 9
Warning: mysqli_connect(): Error while reading greeting packet. PID=10848 in C:\Program Files\apache24\Apache24\htdocs\PhpProject3\php_DataBase.php on line 9
Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\Program Files\apache24\Apache24\htdocs\PhpProject3\php_DataBase.php on line 9
第9行是database=mysqli_connect("localhost:82","root"," ")
答案 0 :(得分:1)
此行中出错,同时也删除了密码中的空格
$datbase=mysqli_connect("localhost:82","root"," ");
您没有连接到MySQL,而是连接到Apache服务器。如果您没有更改MySQL端口,请使用
$datbase=mysqli_connect("localhost","root","","databaseName");
答案 1 :(得分:0)
您应该先阅读http://php.net/manual/en/function.mysqli-connect.php。
$link = mysqli_connect("host", "my_user", "my_password", "my_db");
试试这个:
$datbase=mysqli_connect("localhost","root","","my_db");
if(!$datbase)
{
die("connection failed".mysqli_connect_error());
}
答案 2 :(得分:0)
用
替换此行 $datbase=mysqli_connect("localhost:82","root"," ");
这一个
$datbase=mysqli_connect("localhost","root","","your database name");
答案 3 :(得分:0)
您正在使用localhost上未在php.ini
文件
试试这个
//$datbase=mysqli_connect("localhost","username","password","databaseName");
$datbase=mysqli_connect("localhost","root","","databaseName");
答案 4 :(得分:0)
如果您的Mysql
服务器以default settings
运行,则表示。您不需要指定端口号。否则,您需要将port number
指定为5th
参数。如下例所示。
Mysql默认端口号为3306
$datbase=mysqli_connect("localhost","username","password","database_name","port_number");
if(!$datbase)
{
die("connection failed".mysqli_connect_error());
}