Warning: mysqli_connect(): MySQL server has gone away

前端 未结 2 1220
忘掉有多难
忘掉有多难 2021-01-13 13:01

I wrote a simple php code to connect to the mysql server as below

    

        
相关标签:
2条回答
  • 2021-01-13 13:50

    The error is here:

    $hostname = "localhost:81";
    

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

    $hostname = "localhost";
    
    0 讨论(0)
  • 2021-01-13 13:54

    you forget to specify the database name after entering database name try again. The syntax should be like this

    <?php
    $con = mysqli_connect("localhost","my_user","my_password","my_db");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    ?>
    
    0 讨论(0)
提交回复
热议问题