-1

This is my code for connecting to database:

$datbase=mysqli_connect("localhost:82","root"," ");
if(!$datbase)
{
    die("connection failed".mysqli_connect_error());
}

it shows me that

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

line number 9 is database=mysqli_connect("localhost:82","root"," ")

Paul Karam
  • 4,052
  • 8
  • 30
  • 53
mohitmonu
  • 117
  • 1
  • 2
  • 7
  • 4
    Possible duplicate of [MySQL Server has gone away when importing large sql file](https://stackoverflow.com/questions/12425287/mysql-server-has-gone-away-when-importing-large-sql-file) – Linus Jun 13 '17 at 06:31

5 Answers5

1

Error in this line and also remove space in password

$datbase=mysqli_connect("localhost:82","root"," ");

You are not connecting to MySQL, but to Apache server. If you didn't change MySQL port just use

$datbase=mysqli_connect("localhost","root","","databaseName");
Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
0

You should read first http://php.net/manual/en/function.mysqli-connect.php.

$link = mysqli_connect("host", "my_user", "my_password", "my_db");

Try this:

$datbase=mysqli_connect("localhost","root","","my_db");
if(!$datbase)
{
    die("connection failed".mysqli_connect_error());
}
Paul Karam
  • 4,052
  • 8
  • 30
  • 53
Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
0

Replace this line with

 $datbase=mysqli_connect("localhost:82","root"," ");

with this one

   $datbase=mysqli_connect("localhost","root","","your database name");
0

you are using port number on localhost that you are not set in php.ini file

try like this

//$datbase=mysqli_connect("localhost","username","password","databaseName");

$datbase=mysqli_connect("localhost","root","","databaseName");
Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33
0

If your Mysql server is runs with default settings means . you don't need specify the port number . otherwise you need to specify port number as 5th parameter . like below Example .

Mysql default port number is 3306

$datbase=mysqli_connect("localhost","username","password","database_name","port_number");
if(!$datbase)
{
     die("connection failed".mysqli_connect_error());
}
JYoThI
  • 11,977
  • 1
  • 11
  • 26