douqiang4245
douqiang4245
2017-06-13 06:16

当我以前用php编程语言中使用netbeans连接phpmyadmin时,我遇到了一些错误

已采纳

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"," ")

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • dongtang5776 dongtang5776 4年前

    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");
    
    点赞 评论 复制链接分享
  • duan20145 duan20145 4年前

    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());
    }
    
    点赞 评论 复制链接分享
  • duanliang5051 duanliang5051 4年前

    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");
    
    点赞 评论 复制链接分享
  • duanping2695 duanping2695 4年前

    Replace this line with

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

    with this one

       $datbase=mysqli_connect("localhost","root","","your database name");
    
    点赞 评论 复制链接分享
  • dtnpf35197 dtnpf35197 4年前

    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());
    }
    
    点赞 评论 复制链接分享