0
votes

I'm using cPanel server and I'm getting this error.

Lost connection to MySQL server at 'reading initial communication packet', system error: 0

Although i read his question Lost connection to MySQL server at 'reading initial communication packet', system error: 0 , I still didn't get the solution. when i run my php code, it returns

"Connection successfulLost connection to MySQL server at 'reading initial communication packet', system error: 0"

here's the code:

$con = mysql_connect('mysite.com:2082', '[email protected]', 'passwordhere', 'dbname');

if (mysqli_connect_errno($con))
  {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else
{
    echo "Connection successful";
}
if ($selected = mysql_select_db("dbname",$con) or die(mysql_error())){
    echo "Your database name is dbname";
}


mysqli_close($con);

thanks for answering.

1

1 Answers

0
votes

I was able to sort it out. here's the code:

    $con = mysql_connect('localhost', 'serverusername', 'serverpassword');

    if (mysqli_connect_errno($con))
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $selected = mysql_select_db("db_name",$con) or die(mysql_error());