0

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', 'me@mysite.com', '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.

Community
  • 1
  • 1
Jben Kaye
  • 171
  • 1
  • 5
  • 16

1 Answers1

0

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());
Jben Kaye
  • 171
  • 1
  • 5
  • 16